Reputation: 16128
I implemented a listview with 2 kinds of rows from here listViews with multiple rows tutorial
all is working properly,
the problem that I have now is setting the height for the rows,
if I leave the background as a color, all is good,
but if I use an image for background, I only get a tall row [on other simple list views the height respect the programatically set height], but in this case, the row changes
so
<?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>
works fine,
but
android:background="@drawable/phone_cat_cell">
is not respecting the assigned height,
how to fix this height using my image background?
thanks!
edit 1, adapter
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);
}
}
Upvotes: 3
Views: 10566
Reputation: 7439
Try this:
<ImageView
android:id="@+id/image"
android:layout_width="40dp"
android:layout_height="70dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:gravity="center_vertical"/>
Upvotes: 2
Reputation: 353
Check your adapter code, if you are passing null while inflating the view then please replace that code with this.
view = inflater.inflate(R.layout.listview_row, parent, false);
Upvotes: 3
Reputation: 950
you just need to make not static images, but "9patch" images. All android versions are supporting that. Have a look here http://developer.android.com/tools/help/draw9patch.html
Upvotes: 2