RelativeLayout在1.5和2.1之间的差异

时间:2010-05-17 15:22:03

标签: android listview relativelayout

我有一个ListView,其中的项目由RelativeLayouts组成。这是列表项中的相关XML:

<?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>

在Android 2.1(在Nexus One上测试)中,显示了所需的行为:Android 1.5 http://img42.imageshack.us/img42/7668/85324076.png

在Android 1.5上(在HTC Hero上测试过),它显示如下:Android 1.5 http://img257.imageshack.us/img257/2849/72229324.png

[edit]在1.6(模拟器)上,它也按预期工作。

左上方的小灰线是第一张照片中显示的“xx”,因此应该垂直居中。据我所知,XML决定了这一点,但出于某种原因,1.5忽略了它。

这是为什么?我找不到任何有关这种差异的信息,而且我一直强行使用layout_center,center,alignParent *的任何组合,但无济于事......

有人可以对此有所了解吗?谢谢!

3 个答案:

答案 0 :(得分:1)

对于相对布局,未使用layout_gravity

此外,您使用的是相互矛盾的属性centerInParentalignParentLeft

只使用其中一个。

您可以使用layout_centerVertical="true" layout_alignParentLeft="true"

答案 1 :(得分:1)

RelativeLayout在1.6和2.0中收到许多错误修复:)

答案 2 :(得分:0)

首先,根据你在测试的最早版本中破坏它并在后续版本中按预期工作的事实来判断......听起来像是一个修复过的错误。

然而,除非我过于简单化,因为你只展示了一些基本的样本截图,我还是会用嵌套的LinearLayouts来做这件事。

相关问题