开发者

Why TextViews running into each other in RelativeLayout

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_alignPar开发者_Python百科entTop="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 http://janusz.de/~janusz/view.png

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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜