2013-03-16 27 views
0

這是一個textview可能有長文本的一面。它流過並將屏幕上的一半額定值欄推下。我有一個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> 

回答

0

,你可以檢查字符串的長度,如果大於設定的長度更大,在字符串

結束這樣做...但你TextView的你設置wrap_context也只是使其難以寬度,以便它不會改變

0

您可以在文本視圖中使用下面的屬性

android:layout_toLeftOf="@id/myRatingBar" 

你也可以給一個特定的寬度到您的TextView在XML

android:layout_width="wrap_content" 

,你也可以使用下面的屬性來限制文本視圖

android:maxLength="" 
+0

此屬性只在'RelativeLayout' – nicopico 2013-03-16 16:34:47

+0

theyre裏面沒有相對佈局 – code511788465541441 2013-03-16 16:34:52

+0

我編輯了我的答案,您可以限制文本視圖的長度 – 2013-03-16 16:36:17

0

使用android:maxLines="1"的長度。如果TextView中的文本很長,並且不會將關閉的評分關閉,那麼這會切斷TextView中的文本。

0

既然你的android:layout_weight="1"設置爲兩種觀點,那麼我認爲你可以做android:layout_width="match_parent"

這將使這兩種觀點都有相同寬度的一半家長的寬度。或者你可以根據你想要的值來修改權重字段。

相關問題