2014-07-20 42 views
0

我正在使用包含TableRows的TableLayout。 的TableLayout:未正確處理TextView溢出

 <TableLayout 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:background="@drawable/window" 
      android:minWidth="256dp" 
      android:id="@+id/charStanceList"></TableLayout> 

這些行從該XML文件充氣:

<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="None" 
     android:id="@+id/stanceHands" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="@color/list_text" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="None" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:id="@+id/stances" 
     android:textColor="@color/list_text" /> 

</TableRow> 

這裏是用來創建行的代碼:

public TableRow createTableRow(Context context) { 
     TableRow row =(TableRow) ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.stance_list_row,null); 
     TextView hands=(TextView)row.findViewById(R.id.stanceHands); 

     hands.setText(RHand + LHand); 

     TextView stancesView =(TextView)row.findViewById(R.id.stances); 

     MovementMethod movementMethod = stancesView.getMovementMethod(); 
     if ((movementMethod == null) || !(movementMethod instanceof LinkMovementMethod)) 
     { 
      stancesView.setMovementMethod(LinkMovementMethod.getInstance()); 
     } 
     SpannableString finalss=new SpannableString(""); 
     for (Stance s : stances) { 
      SpannableString ss = new SpannableString(s.getName()); 

      class StanceLink extends ClickableSpan{ 
       Stance stance; 
       @Override 
       public void onClick(View view) { 
        Log.i("Clicked", "clicked on stance "+stance.getName()+" of ClassID "+stance.ClassID); 
       } 
       public void setStance(Stance st){ 
        stance=st; 
       } 
      } 
      StanceLink link=new StanceLink(); 
      link.setStance(s); 
      ss.setSpan(link, 0, s.getName().length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE ); 
      finalss= new SpannableString(TextUtils.concat(TextUtils.concat(finalss,ss),"\n")); 
     } 
     stancesView.setText(finalss); 
     return row; 
    } 

下破線當字符串太寬時插入,但其一部分將被隱藏(在右側)。在這個圖像中使用的文本是:武術五本書 - ...的書... 「藝術 - 」似乎溢出,所以我們看不到它。 這裏的問題是

screenshot

更改Ellipsize不起作用的屏幕截圖。

+0

檢查父佈局中不能有'layout_width'設置爲'wrap_content'。 –

+0

我的TableLayout確實是在一個LinearLayout中有layout_width設置爲包裝內容,但整個事情在另一個LinearLayout,它有match_parent,是它的問題?在TableLayout之前我有另一個textview,它工作正常... – Lectem

回答

0

我固定它得益於安卓shrinkColumns和不斷變化的寬度以match_parent

的tablelayout:

 <TableLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/window" 
      android:minWidth="256dp" 
      android:id="@+id/charStanceList" 
      android:shrinkColumns="1"></TableLayout> 

該行

<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="None" 
     android:id="@+id/stanceHands" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="@color/list_text" /> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="None" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:id="@+id/stances" 
     android:textColor="@color/list_text" /> 

</TableRow>