Android 截断AppWidget布局上的文本视图';s
人们 好吧,在谷歌搜索了将近两天没有结果后,我决定在这里提问。(这是我的第一个问题。) 我正在为Android创建一个quotes小部件(每次显示一个随机引用),因此它有两个TextView和一个ImageButton来获取一个新的随机引用。第一个文本视图显示引用文本,第二个视图显示引用的作者。而且,当用户单击小部件时,它会调用一个活动,全屏显示报价,如果需要,还会显示滚动条,以此类推 问题是引用的文本有时很长,所以我想省略它。但是由于省略不能处理超过2行的内容。。。我在找主意 我不知道是否有必要,但这是布局代码Android 截断AppWidget布局上的文本视图';s,android,textview,truncate,multiline,android-appwidget,Android,Textview,Truncate,Multiline,Android Appwidget,人们 好吧,在谷歌搜索了将近两天没有结果后,我决定在这里提问。(这是我的第一个问题。) 我正在为Android创建一个quotes小部件(每次显示一个随机引用),因此它有两个TextView和一个ImageButton来获取一个新的随机引用。第一个文本视图显示引用文本,第二个视图显示引用的作者。而且,当用户单击小部件时,它会调用一个活动,全屏显示报价,如果需要,还会显示滚动条,以此类推 问题是引用的文本有时很长,所以我想省略它。但是由于省略不能处理超过2行的内容。。。我在找主意 我不知道是否有必
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/laySmall"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="@dimen/widget_margin"
android:background="@drawable/widgetback" >
<ImageButton
android:id="@+id/ibtNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:background="@null"
android:contentDescription="@string/app_name"
android:src="@drawable/seta" />
<TextView
android:id="@+id/txtWdgQuote"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/ibtNext"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="8dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="italic"
android:typeface="serif"
android:maxLines="3" />
<TextView
android:id="@+id/txtWdgAuthor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="bold" />
</RelativeLayout>
这个解决方案的问题是换行符在哪里,因为它可以改变可以显示的字符串的大小。例如,让我们说一个包含小词的字符串:这些行将在边界旁边断开。同时,一个字数较大的字符串的换行符将远离边界
所以。。。我不知道我在做什么。有什么想法吗
谢谢
(我的android:layout_边距有问题,所以可以稍微小一点,但我还没有时间做这件事。为什么要选框文本my Friends,但选框不适用于单行文本视图?(另外,应该是>某物+5,因为你添加了5个字符是的,你说得对。“+5”是必要的。关于maxLines,njzk2,它以一种突然的方式结束文本。不会在结尾放“…”或任何东西。无论如何,在代码中截断它的想法有它的问题…例如,关于屏幕大小:/
if (quoteText.length() > something) {
quoteText = quoteText.substring(0, something) + "\"[...]"
}