2012-03-07 5 views
1

私はカスタム行のリストビューを持っています。 imageView1ではイメージを設定しましたが、行の高さよりも小さくなっています。画像サイズは4x30pxです。 40x300 imgのサイズを設定すると(プログラムで)、行が大きすぎます(理由はわかります:wrap_content)。行の高さに画像が高さで収まるように設定するにはどうすればよいですか?カスタムリストビュー内のAndroidイメージの高さ

holder.image.setImageDrawable(convertView.getResources().getDrawable(R.drawable.priority_4x30)); 

jar.xmlファイル:

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
    > 
     <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/icon" 
     android:focusable="false" /> 

     <TextView android:id="@+id/textView1" 
     android:layout_width="180dip" 
     android:layout_height="wrap_content" 
     android:paddingTop="15dip" 
     android:paddingBottom="15dip" 
     android:textColor="#000000" 
     android:layout_toRightOf="@+id/imageView1"> 
     </TextView> 

     <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/icon" 
     android:layout_toRightOf="@+id/textView1" /> 

     <CheckBox android:id="@+id/checkBox1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="6sp" 
     android:focusable="false" 
     android:layout_toRightOf="@+id/imageView2"> 
     </CheckBox> 

    </RelativeLayout> 
+0

おそらくアンドロイドを追加する:layout_alignParentTop = "true" android:layout_alignParentBottom = "true"をImageViewに追加すると、これが伸びます。また、ストレッチのためのプロパティがありますが、私はそれが今の名前を覚えていない:) – zapl

+0

android:scaleTypeそれは – zapl

答えて

6

あなたは、各項目のためのあなたのrelativelayoutは、静的な高さ

元持たせる必要があります。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight"> 

をし、その後、あなたは単にあなたを変更することができます親をその高さで塗りつぶすための画像ビュー

<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:src="@drawable/icon" 
    android:layout_toRightOf="@+id/textView1" /> 
+0

ありがとう、これは良いです。 RelativeLayoutをLinearLayoutに変更することも、この問題を解決します。 – erdomester

関連する問題