2012-07-18 4 views

답변

6

사용 TableLayout 그것은 나머지 공간을 점유하는 제 2 열을 뻗어

strechColumns = "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

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

고마워요! 잘 작동합니다. 나는'strechColumns '를 가리 키기 때문에 @mussharapp 대답을 받아 들였다. – hsz

-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이어야합니다.

관련 문제