views:

198

answers:

2

I have a problem with two Textviews on the same height in a RelativeLayout running into each other.

I use the following Layout.

<?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="fill_parent">

<ImageView android:id="@+id/logo" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:adjustViewBounds="true"
    android:scaleType="centerInside" android:src="@drawable/icon" />

<TextView android:id="@+id/name" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:text="NameNameNameNameNameNameName"
    android:layout_alignParentTop="true" android:layout_toRightOf="@id/logo"
    android:gravity="clip_horizontal" android:lines="1" />

<TextView android:id="@+id/information" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="Distance"
    android:layout_alignParentRight="true" android:layout_alignParentTop="true" />

<TextView android:id="@+id/nrcoupons" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="Number"
    android:layout_alignRight="@id/information" android:layout_alignBottom="@id/logo" />

<TextView android:id="@+id/subcategory" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="Subcategory"
    android:layout_alignLeft="@id/name" android:layout_alignBottom="@id/logo" />

</RelativeLayout>

This gives me this view:

alt text

Everything is as I need it except the two textviews name and information are displayed on the same screen space with the one on top of the other.

How can I avoid this?

A: 

Your namenamename textview is set with width = fill_parent so you can't put anything to its right ;)

Sephy
changing this to wrap_content does not change anything. And there is something put to its right and is displayed as you can see in the image. Sadly it is displayed beyond the other view
Janusz
+2  A: 

For your @+id/name TextView, add android:layout_toLeftOf="..." for whatever TextView is on the right. The screenshot and the XML do not seem to line up (screenshot appears to have "Distance" in the overwritten TextView, but the XML does not), so I'm not completely certain which widget this is.

If you are targeting Android 1.5, you will need to order the widgets in the XML such that the widgets are defined before they are referenced from android:layout_toLeftOf or android:layout_toRightOf. If you are targeting Android 1.6 and newer only, you can have them be in any order, but the first occurrence of any distinct ID must have the + sign, even if that first occurrence is in an android:layout_toLeftOf attribute instead of an android:id attribute.

CommonsWare
Thank you that resolved my problem. You are right I changed the code after taking the screenshot...
Janusz