3

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

在此处输入图像描述

<?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>
4

3 回答 3

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>
于 2012-07-03T04:29:52.573 回答
0

这肯定会发生,因为RelativeLayout,每当您有一些大长度的文本时。

要克服这个问题,您可以尝试用RelativeLayoutLinearLayout 替换,并android:layout_weight为您TextViewImageView

于 2012-07-03T04:30:08.790 回答
0

您可以将布局宽度和高度设置为以 dp 为单位,例如 200 dp 以调整布局。通过减小尺寸,您的布局可以很好地调整

于 2012-07-03T04:42:59.217 回答