RelativeLayout differences between 1.5 and 2.1
I've got a ListView with items composed of RelativeLayouts. This is the relevant XML from the list items:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/xx"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_centerInParent="true"
android:layout_alignParentLeft="true"/>
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/xx" />
<TextView
android:id="@+id/tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/xx"
android:layout_below="@id/title" />
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/tag"
android:layout_below="@id/title" />
</RelativeLayout>
On Android 2.1 (tested on a Nexus One), this shows the desired behavior: Android 1.5 http://img42.imageshack.us/img42/7668/85324076.png
On Android 1.5 however (tested on a HTC Hero), it shows up like this: Android 1.5 http://img257.imageshack.us/img257/2849/72229324.png
[edit] On 1.6 (emulator), it works as expected as well.
The small grey line on the top left is what shows up in the first pic as "xx", so that should be vertically centered. As far as I can see, the XML dictates this, but for some reason, 1.5 ignores it.
Why is this? I can't find anything about this difference, and I've been br开发者_StackOverflow社区ute forcing any combination of layout_center, center, alignParent*, but to no avail...
Can anyone shed some light on this? Thanks!
For relative layout layout_gravity
is not used.
Also, you're using conflicting attribtues centerInParent
and alignParentLeft
.
Use only one of them.
You can use layout_centerVertical="true" layout_alignParentLeft="true"
RelativeLayout receives many bug fixes in 1.6 and then 2.0 :)
For one, judging by the fact that it's broken in the earliest version you're testing with and works as expected in the later versions...sounds like a bug that was fixed.
However, unless I'm oversimplifying because you're only showing a few basic sample screen shots, I would do this with nested LinearLayouts anyway.
精彩评论