TextView在RelativeLayout中重叠

时间:2012-07-03 04:09:11

标签: android android-layout

我有这个ListView布局项。它包括TextView和ImageView。问题是ImageView与TextView重叠。我想要TextView显示省略号或选框。我该如何解决?

enter image description here

<?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"
    android:orientation="horizontal" 
    android:padding="10dip">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name"
        android:textAppearance="?android:attr/textAppearanceLarge" 
        android:inputType="text"
        android:maxLines="1"
        android:scrollHorizontally="true"

        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@+id/imageView1"/>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon" 

        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"        
        />

</RelativeLayout>

3 个答案:

答案 0 :(得分:2)

<?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"
    android:orientation="horizontal"
    android:padding="10dip" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_toLeftOf="@+id/imageView1"
    android:ellipsize="end"
    android:singleLine="true"
    android:text="lots of text here lots of text here"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:src="@drawable/icon" />

</RelativeLayout>

答案 1 :(得分:0)

这肯定会因为 RelativeLayout 而发生,只要你有一些篇幅较长的文字。

要解决此问题,您可以尝试使用LinearLayout替换RelativeLayout,并为android:layout_weightTextView ImageView 属性>

答案 2 :(得分:0)

您可以将布局宽度和高度设置为dp,例如200 dp,以便调整布局。通过缩小尺寸,您的布局可以通过良好的方式进行调整