2012-07-18 71 views

回答

6

使用TableLayoutstrechColumns = "1"

它横跨第二列占据的剩余空间。

<TableLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:stretchColumns="1" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

     <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

     <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

     <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 
    </TableRow> 

</TableLayout> 
+0

谢谢!效果很好。 – hsz 2012-07-18 10:55:58

2

TableLayout会给你所需的输出:

<TableLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:stretchColumns="1"> 
    <TableRow> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Bla bla bla" 
      android:singleLine="true" />   <!-- first column's view --> 

     <EditText 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> <!-- second column's view --> 
    </TableRow> 

    ... 

</TableLayout> 
+0

谢谢!效果很好。我已经接受了@ mussharapp的答案,因为指向了'strechColumns' - 只是为了更多的开发者。 – hsz 2012-07-18 10:55:40

-1

试试这个:

<?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="horizontal" > 



     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="vertical"> 


      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Label 1" 
       android:layout_marginLeft="7dp" 
       android:layout_marginTop="20dp"/> 
      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Label Loooong2" 
       android:layout_marginLeft="7dp" 
       android:layout_marginTop="30dp"/> 
      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Label 3" 
       android:layout_marginLeft="7dp" 
       android:layout_marginTop="30dp"/> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:orientation="vertical"> 

      <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="TextBox"/> 
      <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="TextBox"/> 
      <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="TextBox"/> 
     </LinearLayout> 


</LinearLayout> 
0

作为替代方案,你可以做一个的LinearLayout像这样:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="100" 
    android:gravity="center_vertical"> 
    <LinearLayout 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="40"> 
     <TextView 
      android:layout_weight="1" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:text="A very very very long text" 
      android:singleLine="true" 
      android:scrollHorizontally="true" 
      android:ellipsize="end"> 
     </TextView> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="60"> 
     <EditText 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="TextBox"> 
     </EditText> 
    </LinearLayout> 
</LinearLayout> 

要调整列的宽度,修改每一个的LinearLayout容器layout_weight。较小的值意味着较小的宽度,并且两个权重必须等于100.

相关问题