2012-10-03 38 views
0

enter image description here我有一個用戶界面,在其中顯示了客戶的詳細信息。現在,一些客戶地址很長,當我在TextView中顯示它時,全屏幕布局向地址Textview的末尾方向移動,因此一些參數隱藏起來。我如何保持地址textview修復的長度。我用ellipsize嘗試過這樣的事情,但沒有運氣。當TextView數據超出其大小時,屏幕向右移動

<style name="CustomerTextView"> 
    <item name="android:layout_width">fill_parent</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:textSize">10sp</item> 
    <item name="android:textColor">@android:color/white</item> 
    <item name="android:layout_margin">5dp</item> 
    <item name="android:background">@drawable/textview_border</item> 
    <item name ="android:ellipsize">end</item> 
    </style> 

,併爲客戶的地址我的XML文件看起來像這樣

<TableRow android:gravity="right" > 

     <TextView 
      style="@style/CustomerLabelTextView" 
      android:gravity="right" 
      android:text="@string/customerAddress" /> 
    </TableRow> 

    <TableRow 
     android:gravity="right" > 


     <TextView 
      android:id="@+id/customerAddress" 
      style="@style/CustomerTextView" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1.0" 
      android:gravity="right" /> 

    </TableRow> 
+0

附上截圖 –

+0

我想,但這裏 – ZAJ

+0

當你點擊編輯有添加圖片的選項如何附上截圖。 –

回答

1

您可以使用android:maxEmsandroid:maxLengthandroid:maxWidth在佈局來控制你的TextView的寬度。您還可以使用android:maxLines來控制TextView將採用的行數。我已將maxEms行添加到TextView聲明中。

 <TextView 
      android:id="@+id/customerAddress" 
      style="@style/CustomerTextView" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1.0" 
      android:maxEms="25" 
      android:gravity="right" /> 
+0

我需要在我的stype或xml文件中使用這個 – ZAJ

+0

您可以將這些添加爲XML佈局文件中的TextView屬性。我更喜歡使用maxEms而不是其他兩個。只要嘗試不同的值,直到找到一個有效的值。 –

+0

我把它添加到了我的樣式文件中,它工作正常。是否可以使用寬度或無 15dp ZAJ