Overlapping TextView items in RelativeLayout in 2.2; no problem in 1.6
-
26-09-2019 - |
Question
I have a problem with a RelativeLayout
containing two TextView
s and a ImageView
, that I use for displaying items in a ListView
. The items are correctly displayed on Android 1.6, but on Android 2.2 the TextView
s are overlapping.
Here is an image that shows the correct and incorrect behavior side-by-side:
And here is the source code of my RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
/>
<TextView
android:id="@+id/secondLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:layout_below="@+id/firstLine"
android:layout_toRightOf="@id/icon"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
/>
<TextView
android:id="@+id/firstLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:ellipsize="marquee"
android:singleLine="true"
android:layout_toRightOf="@id/icon"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
Any idea what I am doing wrong?
Thanks a lot,
Philipp
Solution
This is basically the same answer as Octavian's, but I don't think he actually explained it very well.
You have contradicting statements in your XML file. You have:
android:layout_alignParentBottom="true"
in both of your text views. You also have:
android:layout_below="@+id/firstLine"
in one of the textviews. Essentially, your trying to align to the bottom of a relative layout and then trying to put something under it. There isn't anything "under the bottom."
Remove this contradicting logic and it should solve your problem.
OTHER TIPS
I'm not 100% sure if it is the problem but on your TextView
with the ID firstLine
it seems like you are aligning it to it's parents bottom like you do with TextView
ID secondLine
. I'm quite sure you wanted to say android:layout_alignParentTop="true"
instead.
I can't tell why it is working on Android 1.6 but not on 2.2.