我在Android中有一个listview,它是动态加载的。列表视图持有一个图像,并在上面显示图像的描述,理想情况下,该图像应占图像高度的20%。如何检查位于列表中图像视图顶部的文本视图是否达到图像的20%的最大高度?
正如你从屏幕截图中看到的那样,“哈维‘s- -check在赢得免费汉堡选择器的机会,ON”是适合文本视图的2行,有时如果我的安卓设备是小的,它超过了背景(黑色)的视图,看起来很糟糕。我需要停止这一点,所以我决定,如果字符串在我的文本视图中溢出,我必须截断它。
如何截断文本视图上的字符串,以便一旦达到图像视图高度的20%,图像描述就以“.”结尾。
我目前拥有的xml如下所示。注意,com.parse.myPackage.AspectRatioImageView只是一个图像视图的自定义视图
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF" >
<com.parse.myPackage.AspectRatioImageView
android:id="@+id/campaignImageLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/blank" />
<FrameLayout
android:id="@+id/frameLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/frameLayout2"
android:layout_alignParentLeft="true"
android:background="@color/fadedBlack">
<TextView
android:id="@+id/campaignNameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading..."
android:layout_marginLeft="10dp"
android:textColor="@color/white"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</FrameLayout>
<FrameLayout
android:id="@+id/frameLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/campaignImageLabel"
android:layout_alignParentLeft="true"
android:background="@color/fadedBlack">
<TextView
android:id="@+id/campaignLocationLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Location Loading..."
android:textColor="@color/white"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</FrameLayout>
发布于 2013-11-18 06:32:26
在你的TextView上试试这个
android:maxLines="2"
android:ellipsize="end"
这将截断您的文本和位置“.”如果长度超过2行,则在末尾
发布于 2013-11-18 06:36:14
您可以使用:
android:ellipsize="end"
android:maxLines="1"
更改maxlines
的值,以手动检查是什么使其使您的图像视图的高度20%。ellipsize
会处理‘.’终止。
https://stackoverflow.com/questions/20050185
复制