2012-02-02 7 views
3

私はアンドロイドプロジェクトに取り組んでいます。私はScrollViewsを処理して画像をスクロールする必要があります。しかし、ImageViewScrollViewの中に入れて使用しているとき、私に与えられた画像はUIレイアウトに収まりません。だから私はScrollViewImageViewに変換すると思っています。アンドロイドに手続きがありますか? Plz助けてください。ImageViewのScrollViewの内部

+0

をあなたのXMLを投稿してください。 – Ghost

答えて

0

あなたのエミュレータ画面の中にあなたのイメージビューを合わせたいなら、なぜscrollviewを使うのですか? あなたはこの

LinearLayout linLayout = new LinearLayout(this); 

     // load the origial BitMap (500 x 500 px) 
     Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), 
       R.drawable.android); 

     int width = bitmapOrg.width(); 
     int height = bitmapOrg.height(); 
     int newWidth = 200; 
     int newHeight = 200; 

     // calculate the scale - in this case = 0.4f 
     float scaleWidth = ((float) newWidth)/width; 
     float scaleHeight = ((float) newHeight)/height; 

     // createa matrix for the manipulation 
     Matrix matrix = new Matrix(); 
     // resize the bit map 
     matrix.postScale(scaleWidth, scaleHeight); 
     // rotate the Bitmap 
     matrix.postRotate(45); 

     // recreate the new Bitmap 
     Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, 
          width, height, matrix, true); 

     // make a Drawable from Bitmap to allow to set the BitMap 
     // to the ImageView, ImageButton or what ever 
     BitmapDrawable bmd = new BitmapDrawable(resizedBitmap); 

     ImageView imageView = new ImageView(this); 

     // set the Drawable on the ImageView 
     imageView.setImageDrawable(bmd); 

     // center the Image 
     imageView.setScaleType(ScaleType.CENTER); 

     // add ImageView to the Layout 
     linLayout.addView(imageView, 
       new LinearLayout.LayoutParams(
         LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT 
       ) 
     ); 

     // set LinearLayout as ContentView 
     setContentView(linLayout); 

のようなあなたのエミュレータ画面内のあなたのImageViewのを拡張することができますが、あなたがする必要があるすべてはあなたのImageViewのに

android:src="@drawable/hayhouse" 

を追加していることが

+0

返信ありがとうございます。私はそれが使用されるfirtehrのためにスクロールビューを使用する必要があるプロジェクトに取り組んでいます –

+0

ので、私は便利な方法を教えてください。 –

-2

こんにちは、私はあなたがレイアウト内この

<anyLayout> 
    <ScrollView> 
     <RelativeLayout> 

      <ImageView/> 

     </RelativeLayout> 

    </ScrollView> 

</anyLayout> 

スクロールビューの仕事のようなあなたの問題を解決することができると思います。

+0

私は上記と同じですが、私のイメージの解像度はscreen.butの画面beyoundのbeyound私はemulator.soの私はアンドロイドしようとする画面に完全に合うようにする必要があります:バックグラウンドproperty.and .javaファイルに変換しようとする画像ビューへのスクロールビュー。もしどのメソッドがありますかplz tell me.thanks in advance –

-2
<ScrollView> 
     <RelativeLayout> 

      <ImageView/> 

     </RelativeLayout> 

    </ScrollView> 

これは、これを試してみてください、あなた

+0

前のコメントに基づいてxmlでイメージを設定しないでくださいsetbackgroundresourceをクラスファイル – Donald

3

のために動作します:

<?xml version="1.0" encoding="utf-8"?> 
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/scrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <RelativeLayout 
      android:id="@+id/relativeLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:src="@drawable/ic_launcher" 
       android:contentDescription="@string/describe_something_here"/> 

     </RelativeLayout> 

    </ScrollView> 

は、この情報がお役に立てば幸いです。

-3

は、私は非常に簡単な解決策を見つけることができますホープレイアウトxmlファイル内にあります。

17

私はちょうど追加し、あなたのImageViewのパラメータで、素敵な解決策を見つけた -

android:adjustViewBounds="true" 
関連する問題