Android layout bug in 1.6 vs 2.2
I have a strange "bug" in my layout file. I am new to Android, so per开发者_如何学Gohaps I am missing something. I stripped the example down to the bare minimum to ease your understanding of the problem:
I have a simple list, with a ListAdapter, which should display a line of text with an icon next to it. The icon should be centered vertically if the text is higher then the icon.
If I leave the attribute "center" out, the sample works (the list item gets the correct heigth), but as soon as I include it, I get a bug.
Any ideas on how to solve this issue? (btw, I need the tableLayout for streching columns, not sure if there is another way for this)
The XML source for the row looks like this:
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow>
<TextView
android:height="30dp"
android:width="30dp"
android:background="@color/blue"
android:layout_gravity="center_vertical"
/>
<TextView
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="22dp"
android:layout_width="120dp"
android:layout_gravity="left"
android:background="@color/yellow"
android:id="@+id/simple_list_row_text1"/>
</TableRow>
The desired result (which works on higher versions of android without any problems) is:
And the image on Android 1.6
Give the whole TableRow a center_vertical gravity. And of course move the fixed width/height from the TextView to the TableRow, and leave the TextView to wrap_height
Solution workaround is:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center">
<TextView
android:layout_height="30dp"
android:layout_width="30dp"
android:background="@color/blue"
/>
</LinearLayout>
<TextView
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="22dp"
android:layout_width="120dp"
android:layout_gravity="left"
android:background="@color/yellow"
android:id="@+id/simple_list_row_text1"/>
精彩评论