Tuesday, 10 September 2013

Android - having trouble properly sizing an xml layout used for a listview row

Android - having trouble properly sizing an xml layout used for a listview
row

I'm trying to set up an xml layout to be used for a row in a ListView. The
layout consists of a root LinearLayout with a child RelativeLayout
containing two ImageViews (one anchored to the other's bottom/right
corner) and a child vertical LinearLayout containing two TextViews. I want
each row in the listview to have the same width and height, despite the
size of the content in the subviews. I realize I cannot use wrap_content
which will size the views based on their content, but I'm unclear on what
I should use to accomplish a uniform width/height. I tried using fixed dp
values, but that just made it even worse. I've attached two screenshots.
The first one, from the iOS version, shows how it should look, while the
second one shows how it looks on the Android version with the following
layout. As a said, I know what's wrong (the wrap_content attributes), but
how do I change it to size correctly? Thanks in advance!


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/campaign_thumbnail_container" >
<ImageView
android:id="@+id/campaign_thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/campaign_mark_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/campaign_thumbnail"
android:layout_alignRight="@id/campaign_thumbnail"
android:src="@drawable/new1" />
</RelativeLayout>
<LinearLayout
android:id="@+id/campaign_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/word_bar"
android:orientation="vertical" >
<TextView
android:id="@+id/campaign_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/campaign_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/campaign_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/campaign_footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>

No comments:

Post a Comment