3

ImageViewa の中に aを追加したいListView。画像がゆがむことなくレイアウトを埋めるようにしたいと思います(基本的に、高さを埋めて幅を調整します)。

これは私が今得るものです:

ここに画像の説明を入力

ImageView見やすいように背景をグレーにしてみました。赤で、それは私が手に入れたいサイズです.

これが私のコードです:

Project_form.xml

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

     <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/name_project"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:padding="3dp"
        android:layout_alignParentLeft="true"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="25dp" >
    </TextView>

    <Button
        android:id="@+id/button_project"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/btn_custom"
        android:layout_centerVertical="true"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_alignParentRight="true"
        android:padding="3dp"
        android:text="  details  "
        android:textSize="20dp"
        android:visibility="invisible" />

    <ImageView
        android:id="@+id/imagesstep"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:background="@color/grey"
        android:adjustViewBounds="false"
        android:layout_centerVertical="true"
        android:padding="3dp"
        android:layout_alignParentRight="true"
        android:visibility="invisible" />
 </RelativeLayout>

私のメソッド getView()Adapter :

@Override
public View getView(int position, View convertView, ViewGroup parent) {            
    View row = convertView;            
    if (row==null) {       
        LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        row = inflater.inflate(R.layout.project_form, parent, false);
    }   
    TextView text = (TextView) row.findViewById(R.id.name_project); 
    text.setText(this.objects[position].getName());       
    int IDImage=this.objects[position].getIDImage();       
    int IDPlay = this.objects[position].getIDPlay();
    text.setCompoundDrawablesWithIntrinsicBounds(IDImage, 0, 0, 0);         
    text.setCompoundDrawablePadding(7);    
    ImageView image = (ImageView)
    row.findViewById(R.id.imagesstep);                
    image.setVisibility(View.VISIBLE);          
    image.setImageResource(IDPlay);
    if (position == selectedPosition) {
        row.setBackgroundColor(Color.parseColor("#8000ff00"));
    }  
    else {
        row.setBackgroundColor(Color.TRANSPARENT);
    }

    return row;
}

ScaleTypeandroid:adjustViewBounds や layout_widthなどのさまざまなパラメーターを試してみましたが、画像の高さは変わりませんでした。私もプログラムでそれをやろうとしましたが(image.setMinHeight(parent.getHeight())のようなもの)、それも失敗しました。

誰が何が間違っているのか教えてもらえますか?

どうもありがとう

4

2 に答える 2

2

RelativeLayoutの を に変更してみてlayout_heightくださいfill_parent

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

    <TextView ... />

    <Button .. />

    <ImageView ... />
 </RelativeLayout>

minHeightまたは、の属性をにImageView設定することもできます?android:attr/listPreferredItemHeight

<ImageView
    ...
    android:minHeight="?android:attr/listPreferredItemHeight" />
于 2013-02-25T15:28:16.900 に答える
1

イメージビューからパディングを削除します

于 2013-02-25T15:34:38.190 に答える