가로선에 세 개의 버튼 (각각 동일한 너비)이있는 레이아웃을 만들려고합니다.안드로이드에서 그리드와 같은 레이아웃을 만드는 방법
xxxx xxxx xxxx
xxxx xxxx xxxx
X는 버튼을 나타냅니다. 어떻게하면 각 셀에 33 %를 배포 한 다음 스트레칭되지 않는 버튼을 추가 할 수 있습니까?
가로선에 세 개의 버튼 (각각 동일한 너비)이있는 레이아웃을 만들려고합니다.안드로이드에서 그리드와 같은 레이아웃을 만드는 방법
xxxx xxxx xxxx
xxxx xxxx xxxx
X는 버튼을 나타냅니다. 어떻게하면 각 셀에 33 %를 배포 한 다음 스트레칭되지 않는 버튼을 추가 할 수 있습니까?
한 가지 방법은 android:layout_weight="1"
과 더불어, LinearLayout
사용하는 것입니다 :
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<Button
android:text="Button 1"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1" />
<Button
android:text="Button 2"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1" />
<Button
android:text="Button 3"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1" />
</LinearLayout>
TableLayout
: 3 열 2 행, stretchModespacingWidthUniform
을 사용할 수 있어야합니다.
편집 : 시도하지 않았으므로 정상적으로 작동합니다.
<TableLayout android:id="@+id/TableLayout01"
android:layout_height="wrap_content" android:layout_width="fill_parent" android:stretchMode="spacingWidthUniform">
<TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Settings"
android:id="@+id/btnSettings"></Button>
<Button android:text="@+id/Button01" android:id="@+id/Button01"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="@+id/Button02" android:id="@+id/Button02"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:text="@+id/Button03" android:id="@+id/Button03"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="@+id/Button04" android:id="@+id/Button04"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="@+id/Button05" android:id="@+id/Button05"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</TableRow>
</TableLayout>