我希望在ListView
內添加ImageView
。我希望圖像能夠在不扭曲的情況下填充佈局(基本上,填充高度並調整其寬度)。ImageView不填充其佈局的高度
這是我現在得到:
我已經把灰色背景的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;
}
我試圖用這樣的不同的參數來打作爲ScaleType
,android:adjustViewBounds和la yout_width但我的圖像的高度從未改變。我也試着做編程(像image.setMinHeight(parent.getHeight()),但它失敗了。
任何人都可以點我出了什麼錯誤?
非常感謝
感謝。將寬度和高度都設置爲「?android:attr/listPreferredItemHeight」的竅門。 – Gordak 2013-02-25 16:50:05