Reputation: 1467
I tried to make table layout like this in the Android.
First column - 2 buttons, next column one button in second row. The size of the buttons should be the same. I use 0 width and weight 1 and stretch the columns.
In the XML:
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:stretchColumns="*" >
<TableRow>
<Button
android:id="@+id/button_stereo_system_state"
style="@style/StyleButton"
android:background="@drawable/background_button_off"
android:drawableTop="@drawable/icon_button_on_off"
android:text="@string/button_text_option_off" />
<Button
android:id="@+id/button_stereo_system_radio"
style="@style/StyleButton"
android:background="@drawable/background_button_off"
android:drawableTop="@drawable/icon_button_play"
android:text="@string/button_text_play_radio" />
</TableRow>
<TableRow>
<Button
android:id="@+id/button_stereo_system_cd"
style="@style/StyleButton"
android:layout_column="0"
android:background="@drawable/background_button_off"
android:drawableTop="@drawable/icon_button_play"
android:text="@string/button_text_play_cd" />
</TableRow>
</TableLayout>
In the style:
<style name="StyleButton">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_margin">10dip</item>
<item name="android:textSize">19sp</item>
<item name="android:textColor">@color/color_text_button</item>
</style>
With this source code in second row button is stretched and takes the whole row. How to make this?
Upvotes: 0
Views: 729