The relative difference between 1.5 and 2.1

I have a ListView with items consisting of RelativeLayouts. This is the corresponding 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> 

In Android 2.1 (tested on Nexus One) this shows the desired behavior: Android 1.5 http://img42.imageshack.us/img42/7668/85324076.png

However, on Android 1.5 (tested on HTC Hero) it looks like this: Android 1.5 http://img257.imageshack.us/img257/2849/72229324.png

[edit] In 1.6 (emulator), it works just as expected.

The little gray line in the upper left corner is what appears in the first image as “xx”, so it should be vertically centered. As far as I can see, XML dictates this, but for some reason 1.5 ignores it.

Why is this? I cannot find anything about this difference, and I was rude, forcing any combination of layout_center, center, alignParent *, but to no avail ...

Can anyone shed some light on this? Thanks!

+4
source share
3 answers

For relative layout layout_gravity not used.

In addition, you use the conflicting centerInParent and alignParentLeft .

Use only one of them.

You can use layout_centerVertical="true" layout_alignParentLeft="true"

+1
source

RelativeLayout gets many bug fixes in 1.6 and then 2.0 :)

+1
source

For one, judging by the fact that it is broken in the earliest version that you are testing with, and works as expected in later versions ... sounds like a bug fixed.

However, if I do not simplify, because you only show a few basic screenshots of the sample screen, I would do it with the attached LinearLayouts anyway.

0
source

Source: https://habr.com/ru/post/1310007/


All Articles