0

xml的一些细节我不擅长,下一个问题也找不到解决办法。

我有一个列表视图。一行定义如下 xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center_vertical" >

        <TextView
            android:id="@+id/date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textColor="#ff888888"
            android:textSize="10dp"
            android:paddingRight="5dp"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:paddingLeft="5dp"
            android:text="02 OCT"
            android:textStyle="bold"
         />


        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:textColor="#ff000000"
            android:textSize="14dp"
            android:singleLine="true"
            android:ellipsize="end"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:text="GIRLFRIEND COFFE AT STARBUCKS COFFE"
            android:maxWidth="250dip"
         />
         <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:background="@drawable/icon_clip"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:id="@+id/img_posted_check"
        />
        <TextView
            android:id="@+id/relleno"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
             android:layout_weight="1"
            android:textColor="#ff000000"
            android:textSize="14dp"
            android:singleLine="true"
            android:ellipsize="end"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:text=""
         />

        <TextView
            android:id="@+id/amount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#ff000000"
            android:textSize="14dp"
            android:paddingLeft="5dp"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:paddingRight="5dp"
            android:text="$13.34"
         />
</LinearLayout>

如果文字很短,我可以看到: 在此处输入图像描述

但是如果文本描述太长,它会占用所有空间直到窗口的限制,并用“...”进行裁剪,弹出价格和剪辑标记: 在此处输入图像描述

我可以做到这一点,前提是我不使用剪辑将权重属性添加到标题 id (@+id/title) 的文本视图并且没有 ID 为“relleno”的布局。

4

2 回答 2

1

我想这就是你想要的

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:paddingBottom="5dp"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:paddingTop="5dp"
    android:text="02 OCT"
    android:textColor="#ff888888"
    android:textSize="10dp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/img_posted_check"
    android:layout_toRightOf="@+id/date"
    android:ellipsize="end"
    android:maxWidth="250dip"
    android:paddingBottom="5dp"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:paddingTop="5dp"
    android:singleLine="true"
    android:text="GIRLFRIEND COFFE AT STARBUCKS COFFE"
    android:textColor="#ff000000"
    android:textSize="14dp" />

<ImageView
    android:id="@+id/img_posted_check"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp"
    android:layout_toLeftOf="@+id/relleno"
    android:background="@drawable/ic_launcher" />

<TextView
    android:id="@+id/relleno"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/amount"
    android:ellipsize="end"
    android:paddingBottom="5dp"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:paddingTop="5dp"
    android:singleLine="true"
    android:text=""
    android:textColor="#ff000000"
    android:textSize="14dp" />

<TextView
    android:id="@+id/amount"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:paddingBottom="5dp"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:paddingTop="5dp"
    android:text="$13.34"
    android:textColor="#ff000000"
    android:textSize="14dp" />

</RelativeLayout>
于 2012-10-29T17:44:30.357 回答
0

然后你可以用 textview 替换 imageview ..,使用这个

<TextView
        android:id="@+id/img_posted_check"
        android:layout_width="300dp"
        android:gravity="center"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/ic_launcher" 
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"

        android:text="hiiii" />
于 2014-04-23T09:32:06.687 回答