介于1.5和2.1 RelativeLayout的差异 [英] RelativeLayout differences between 1.5 and 2.1
问题描述
我有与RelativeLayouts组成的项目一个ListView。这是从列表项相关的XML:
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>
在Android 2.1的(在Nexus One的测试),这说明所期望的行为:
On Android 2.1 (tested on a Nexus One), this shows the desired behavior:
在Android 1.5的(然而在HTC Hero的测试),它显示了这样的:
On Android 1.5 however (tested on a HTC Hero), it shows up like this:
在1.6(模拟器),它按预期工作为好。
[edit] On 1.6 (emulator), it works as expected as well.
在顶部左边的小灰线是什么显示在第一峰为××,因此应垂直居中。据我所看到的,XML决定这一点,但由于某些原因,1.5忽略它。
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.
这是为什么?我无法找到这种差异什么,我一直暴力破解layout_center的任意组合,中心,alignParent *,但无济于事...
Why is this? I can't find anything about this difference, and I've been brute forcing any combination of layout_center, center, alignParent*, but to no avail...
任何人都可以揭示出这个一些启示?谢谢!
Can anyone shed some light on this? Thanks!
推荐答案
有关相对布局 layout_gravity
不被使用。
For relative layout layout_gravity
is not used.
此外,您使用的是相互冲突的attribtues centerInParent
和 alignParentLeft
。
Also, you're using conflicting attribtues centerInParent
and alignParentLeft
.
使用只是其中之一。
您可以使用 layout_centerVertical =真正的layout_alignParentLeft =真正的
这篇关于介于1.5和2.1 RelativeLayout的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!