[英]I have an textview that overflows no matter what parameters I give it
這是一個textview,可能在其旁邊有長文本。 它溢出,並將一半的額定值欄推離屏幕。
如何使它剪切文本而不關閉等級欄?
<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>
您可以檢查字符串的長度,如果它大於設置的長度,則在字符串末尾執行類似...
的操作
但是您將textview設置為wrap_context
,也可以將其設置為硬寬度,這樣就不會改變
您可以在文本視圖中使用以下屬性
android:layout_toLeftOf="@id/myRatingBar"
您還可以為xml中的textview提供特定的寬度
android:layout_width="wrap_content"
並且您還可以使用以下屬性來限制文本視圖的長度
android:maxLength=""
使用android:maxLines="1"
。 如果文本很長,這將剪切TextView中的文本,並且不會推遲“等級”。
由於您已將android:layout_weight="1"
為兩個視圖,所以我認為您可以執行android:layout_width="match_parent"
這將使兩個視圖具有相同的寬度,該寬度是父視圖的寬度的一半。 或者,您可以根據所需的任何值修改權重字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.