android - 1.5 和 2.1 之间的 RelativeLayout 差异

标签 android listview android-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

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

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

这是为什么?我找不到关于这种差异的任何信息,而且我一直在暴力破解 layout_center、center、alignParent* 的任意组合,但无济于事......

任何人都可以阐明这一点吗?谢谢!

最佳答案

对于相对布局 layout_gravity 不使用。

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

只使用其中一个。

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

关于android - 1.5 和 2.1 之间的 RelativeLayout 差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2850336/

相关文章:

Android Spinner OnItemSelectedListener 无法正常工作

android - 如何使用正确的 View z 顺序在 android 中实现此基本布局

java - 自定义 ListView ,第一行不正确

c# - ListView.SelectedItem 样式 - Windows 应用商店应用

java - Wicket - Ajax PropertyListView

android - 带有嵌套 RelativeLayout 的 SwipeRefreshLayout

android - 重新连接后无法再写入 BLE 设备的特性

android - 找不到满足版本约束的 'com.android.support:support-annotations'版本

Android - 播放完成后无法隐藏 VideoView

android - 如何居中线性布局