Java 如何在android中检查字符串是否从我的视图溢出?
我在Android中有一个动态加载的listview。列表视图包含一个图像,其上显示图像的描述,理想情况下,该图像应占据图像高度的20%。如何检查列表中位于图像视图顶部的文本视图的最大高度是否为图像的20% 正如你从截图上看到的,“哈维店--登记一下,就有机会赢取一个免费汉堡 Picker,ON“在文本视图中有两行,有时如果我的android设备很小,它会超出背景(黑色)视图,看起来很糟糕。我需要停止这样做,所以我决定如果字符串在我的textview上溢出,我必须截断它 如何截断textview上的字符串,以便在达到imageview高度的20%后,图像描述以“…”结尾 下面给出了我目前拥有的xml。请注意,com.parse.myPackage.AspectRatioImageView只是imageview的自定义视图Java 如何在android中检查字符串是否从我的视图溢出?,java,android,textview,android-imageview,Java,Android,Textview,Android Imageview,我在Android中有一个动态加载的listview。列表视图包含一个图像,其上显示图像的描述,理想情况下,该图像应占据图像高度的20%。如何检查列表中位于图像视图顶部的文本视图的最大高度是否为图像的20% 正如你从截图上看到的,“哈维店--登记一下,就有机会赢取一个免费汉堡 Picker,ON“在文本视图中有两行,有时如果我的android设备很小,它会超出背景(黑色)视图,看起来很糟糕。我需要停止这样做,所以我决定如果字符串在我的textview上溢出,我必须截断它 如何截断textvie
<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>
您可以使用:
android:ellipsize="end"
android:maxLines="1"
如果
android:maxLines=“1”
完成了你的工作,那么你可以尝试android:singleLine=“true”
你可以用它来处理截短。你可以添加一些代码和屏幕截图吗?@SList添加了屏幕截图和我的XML,或者删除下一票?你能帮我回答这个问题吗question@AkshatAgarwal-我没有投你反对票-我不想看到问题结束,因为我也不知道答案-但现在看起来好多了-我肯定有人会在一分钟内帮助你的。@SList,谢谢!是的,我现在意识到我最初发布的问题有多糟糕。欣赏积极的批评。