두 개의 열을 포함하도록 UI를 디자인해야합니다.첫 번째 열 wrap_content, 두 번째 fill_parent가있는 두 개의 열 레이아웃
첫 번째 열은 포함 된 레이블을 감싸고 같은 행의 두 번째 열은 전체 공간을 채워야합니다. 몇 가지 예를 아래 :
http://temp.chrzanowski.info/so_layout.png
내가 어떻게 할 수 있습니까?
두 개의 열을 포함하도록 UI를 디자인해야합니다.첫 번째 열 wrap_content, 두 번째 fill_parent가있는 두 개의 열 레이아웃
첫 번째 열은 포함 된 레이블을 감싸고 같은 행의 두 번째 열은 전체 공간을 채워야합니다. 몇 가지 예를 아래 :
http://temp.chrzanowski.info/so_layout.png
내가 어떻게 할 수 있습니까?
사용 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>
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>
고마워요! 잘 작동합니다. 나는'strechColumns '를 가리 키기 때문에 @mussharapp 대답을 받아 들였다. – hsz
이 시도 : 대안으로
<?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>
, 당신이 이렇게 같이있는 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이어야합니다.
감사합니다! 잘 작동합니다. – hsz