2013-11-22 158 views
0

我有以下列表视图的布局文件,但textview的文本与imageview重叠。我的布局内容有什么问题?Android textview与imageview重叠

<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="fill_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginRight="6dip" 
    android:contentDescription="TODO" 
    android:src="@drawable/ic_launcher" /> 


<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@id/secondLine" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_alignWithParentIfMissing="true" 
    android:layout_toRightOf="@id/icon" 
    android:gravity="center_vertical" 
    android:text="Example application" 
    android:textSize="16sp" /> 

</RelativeLayout> 
+0

你能展示一些像你想要的东西和你得到的东西吗? –

+0

我试过你的布局,我没有发现任何问题(除了不存在的@ id/secondLine)。你能发布问题的截图吗? –

回答

0

试试这个.. 变化TextView宽度wrap_content并添加

下面两条线在TextView

android:layout_centerVertical="true" 
android:layout_centerHorizontal="true" 

<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="fill_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_marginRight="6dip" 
    android:contentDescription="TODO" 
    android:src="@drawable/ic_launcher" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" 
    android:text="Example application" 
    android:layout_toRightOf="@+id/icon" 
    android:textSize="16sp" /> 

</RelativeLayout> 
+0

只需注意一下你的布局:如果'text'很长,'TextView'将会覆盖'ImageView'。 –

+0

@AndrewT。检查我的编辑'android:layout_toRightOf =“@ + id/icon”'我加了 – Hariharan

1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:padding="6dip" > 

<ImageView 
    android:id="@+id/icon" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_marginRight="6dip" 
    android:contentDescription="TODO" 
    android:src="@drawable/ic_launcher" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/icon" 
    android:layout_toRightOf="@+id/icon" 
    android:gravity="center_vertical" 
    android:text="Example application" 
    android:textSize="16sp" /> 

</RelativeLayout> 
0
<?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="?android:attr/listPreferredItemHeight" 
android:padding="6dip" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_alignParentLeft="true" 
    android:layout_marginLeft="10dip" 
    android:layout_centerInParent="true" 
    android:src="@drawable/ic_launcher" /> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:layout_marginLeft="20dip" 
    android:layout_centerVertical="true" 
    android:layout_toRightOf="@+id/imageView1" 
    android:text="TextView" /> 

</RelativeLayout>