[英]I have an textview that overflows no matter what parameters I give it
It's a textview that could possibly have long text in side it. 这是一个textview,可能在其旁边有长文本。 it over flows and pushes half of ratings bar off the screen.
它溢出,并将一半的额定值栏推离屏幕。
How can I make it cut the text and not push the ratingsbar off? 如何使它剪切文本而不关闭等级栏?
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="2" >
<TextView
android:id="@+id/rest_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:paddingLeft="3dp"
android:singleLine="true"
android:text="long text goes goes here long text goes goes here long text goes goes here"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RatingBar
android:id="@+id/myRatingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:numStars="5" />
</LinearLayout>
you could check the length of the string and if it is greater than a set length and do something like ...
at the end of the string 您可以检查字符串的长度,如果它大于设置的长度,则在字符串末尾执行类似
...
的操作
but you are setting the textview to wrap_context
you could also just make it a hard width so it wont change 但是您将textview设置为
wrap_context
,也可以将其设置为硬宽度,这样就不会改变
you can use the following attribute in your text view 您可以在文本视图中使用以下属性
android:layout_toLeftOf="@id/myRatingBar"
you can also give a specific width to your textview in xml 您还可以为xml中的textview提供特定的宽度
android:layout_width="wrap_content"
and also you can use the following attribute to limit the length of text view 并且您还可以使用以下属性来限制文本视图的长度
android:maxLength=""
Use android:maxLines="1"
. 使用
android:maxLines="1"
。 This will cut the text in the TextView if it is long and will not push the Ratings off. 如果文本很长,这将剪切TextView中的文本,并且不会推迟“等级”。
Since you have set the android:layout_weight="1"
to both views, then I think you can do android:layout_width="match_parent"
由于您已将
android:layout_weight="1"
为两个视图,所以我认为您可以执行android:layout_width="match_parent"
This will make both views have the same width which is half the parent's width. 这将使两个视图具有相同的宽度,该宽度是父视图的宽度的一半。 Or you could modify the weight field according to whatever value you want.
或者,您可以根据所需的任何值修改权重字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.