2015-03-13 58 views
0

我有以下xml布局 - 如果editText_model文本相当短,那么表格按重量值分割50/50。文本长度很长时会忽略表格权重?

然而,文本越长,文字描述就越多。为什么它忽略了50/50分割?

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 

       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical"> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="100"> 

     <TableRow> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="50" 
       android:paddingLeft="5dp" 
       android:text="Select" 
       android:textSize="15sp"/> 

      <RadioGroup 
       android:id="@+id/radioGroupAdd" 
       android:layout_weight="50" 
       android:orientation="horizontal"> 

       <RadioButton 
        android:id="@+id/RadioModel" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Test1"/> 

       <RadioButton 
        android:id="@+id/RadioPaint" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:text="Test2"/> 

      </RadioGroup> 
     </TableRow> 

    </TableLayout> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="100"> 

     <TableRow> 
      <TextView 
       android:id="@+id/tV_model" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="50" 
       android:gravity="center|left" 
       android:paddingLeft="5dp" 
       android:text="Description" 
       android:textSize="15sp"/> 

      <EditText 
       android:id="@+id/editText_model" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="50" 
       android:hint="Enter Description" 
       android:inputType="text|textMultiLine|textNoSuggestions" 
       android:minLines="3" 
       android:text="testing long line of text 1234567890 123 456 77878 89 9 9d" 
       android:textSize="15sp"/> 


     </TableRow> 
    </TableLayout> 
</LinearLayout> 

enter image description here

回答

3

对于layout_width,尝试把0dp。

+0

谢谢 - 这个伎俩。一直在为此奋斗多年。现在阅读为什么0dp?! – Greg 2015-03-13 13:44:24

+0

你让宽度占据零密度独立像素,但让重量决定应该有多少宽度:) – 2015-03-13 13:48:33