4

我有一个 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

[编辑] 在 1.6(模拟器)上,它也可以按预期工作。

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

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

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

4

3 回答 3

1

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

于 2010-05-17T18:34:26.843 回答
1

layout_gravity不使用相对布局。

此外,您正在使用相互冲突的属性centerInParentalignParentLeft.

仅使用其中之一。

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

于 2010-05-17T18:23:19.220 回答
0

一方面,从它在您正在测试的最早版本中被破坏并且在更高版本中按预期工作的事实判断......听起来像是一个已修复的错误。

但是,除非我过于简单化,因为您只显示了一些基本的示例屏幕截图,否则无论如何我都会使用嵌套的 LinearLayouts 来做到这一点。

于 2010-05-17T18:18:38.397 回答