我从这里实现了一个列表视图,其中包含两种行 listViews with multiple rows tutorial 一切正常, 我现在的问题是设置行的高度, 如果我把背景留作颜色,一切都很好, 但是如果我使用一个图像作为
一切正常,
我现在的问题是设置行的高度,
如果我把背景留作颜色,一切都很好,
但是如果我使用一个图像作为背景,我只会得到一个很高的行[在其他简单的列表视图中高度尊重编程设置的高度],但在这种情况下,行更改
所以
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/category_item_row" android:orientation="horizontal" android:layout_width="fill_parent" android:background="#ff00ff" android:layout_height="70dp" android:padding="3dp" > <ImageView android:id="@+id/image" android:layout_width="40dp" android:layout_height="70dp" android:gravity="center_vertical"/> <TextView android:id="@+id/title" android:textSize="20sp" android:layout_width="90dp" android:layout_height="70dp" android:gravity="center_vertical"/> </LinearLayout>
工作良好,
但
android:background="@drawable/phone_cat_cell">
不尊重指定的高度,
如何使用我的图像背景修复此高度?
谢谢!
编辑1,适配器
listViewItem.setAdapter(new PhoneItemAdapter(new ItemPhoneDataSource().getItems()));
private class PhoneItemAdapter extends BaseAdapter {
final List<RowPhone> rows;//row
//data source, style
PhoneItemAdapter(List<ItemPhone> animals) {
rows = new ArrayList<RowPhone>();//member variable
//choose cell! iterator
for (ItemPhone item : animals) {
//if it has an image, use an ImageRow
if (item.getImageId() != null) {
rows.add(new RowFolderPhone(LayoutInflater.from(getActivity()), item)); //imageRow!
} else {//otherwise use a DescriptionRow
rows.add(new RowItemPhone(LayoutInflater.from(getActivity()), item));
}
}
}
//delegate
@Override
public int getViewTypeCount() {
return RowTypePhone.values().length;
}
@Override
public int getItemViewType(int position) {
//con cast
return ((RowPhone) rows.get(position)).getViewType();
}
public int getCount() {
return rows.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
//cambiado con cast!
return ((RowPhone) rows.get(position)).getView(convertView);
}
}
你只需要制作非静态图像,而不是“9patch”图像.
所有Android版本都支持它.
看看这里 http://developer.android.com/tools/help/draw9patch.html
