2012-02-20 26 views
1

我有一個佈局,我把i行動態地放在scrollview內的tablelayout中。除了我不能獲得checkbox文本到wordwrap(請參閱下面的xml)之外,所有內容都運行正常。文本也在運行時設置。我已經搜索了互聯網,並且已經做了很多嘗試設置不同的屬性,但沒有運氣。如何wordwrap複選框文本?

這個任務可能實現嗎?

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="15dip"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <CheckBox 
      android:id="@+id/bes_checkbox" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" /> 

     <EditText 
      android:id="@+id/bes_kommentar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/bes_checkbox" /> 

    </RelativeLayout> 

</TableRow> 
+0

你是什麼意思wordwrap? – 2012-02-20 12:13:14

+0

他意味着他不希望文本內容被切斷。他希望它自動換行到下一行。 – Shoerob 2014-04-14 13:03:32

+0

我認爲如果你將複選框的maxWith屬性設置爲像150dp這樣的常量,它會包裝它的文本。 – 2016-07-13 12:04:38

回答

2

CheckBox extends TextView,所以我認爲像他們解決的問題在這篇文章中你可以用它的文字:

如果你不能得到它這樣的工作,你也可以嘗試在checkbox中使用match_parent

 <CheckBox 
     android:id="@+id/bes_checkbox" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="" /> 

希望它有幫助。線性佈局而不是表佈局內

+0

我在RunTime生成'Table Layout'並且面對與CheckBox相同的問題。 在'layoutParams'中將'height'設置爲'matchParent'幫助了我。 我已經將寬度設置爲0dp。 它爲我工作,因此我upvoted。 我不這麼認爲,我會考慮將'height'設置爲'matchParent'而不通過這個帖子 – DeltaCap 2013-08-02 14:07:54

-1

使用錶行..

 android:id="@+id/linearLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

    <TableRow 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="15dip" > 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <CheckBox 
       android:id="@+id/bes_checkbox" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
      /> 

      <EditText 
       android:id="@+id/bes_kommentar" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/bes_checkbox" /> 
     </RelativeLayout> 
    </TableRow> 

    <TableRow 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="15dip" > 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <CheckBox 
       android:id="@+id/bes_checkbox" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       /> 

      <EditText 
       android:id="@+id/bes_kommentar" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/bes_checkbox" /> 
     </RelativeLayout> 

    </TableRow> 
</LinearLayout> 
-1

我已經作出動態佈局與過去的複選框,並用這種方法:

// Create new view to add layout to 
sv = new ScrollView(this); 
// Create new layout to add check boxes to 
ll = new LinearLayout(this); 
ll.setOrientation(LinearLayout.VERTICAL); 
// Add layout to view 
sv.addView(ll);  

// Create 6 check boxes 
int itemSize = 6; 
for(int j=0; j<itemSize; j++){ 
    CheckBox cb = new CheckBox(this); 
    cb.setText("number " + j); 
    ll.addView(cb); 
} 
// Finalize view 
this.setContentView(sv); 

這就是你正在找?