Android Tablelayout Remove Padding
What I'm trying to do is to remove every padding and margin from a TableLayout, and display the children buttons tiled. This is the activity_main.xml code
Solution 1:
Both TableLayout
and TableRow
are LinearLayouts
. So using the weight
attribute will give you the desired result:
- Set
TableLayout's
width and height tomatch_parent
- Set
layout_height="0dp"
andlayout_weight="0.5"
for theTableRows
to make them fit 50% of the screen height each; - Set each
Button's
height tomatch_parent
to fill the row's height, and also set itslayout_width="0dp"
andlayout_weight="0.5"
to fit the row's width equally.
Here is the layout:
<TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TableRowandroid:layout_width="wrap_content"android:layout_height="0dp"android:layout_weight="0.5"><Buttonandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="0.5"android:text="New Button"android:id="@+id/button1" /><Buttonandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="0.5"android:text="New Button"android:id="@+id/button4" /></TableRow><TableRowandroid:layout_width="wrap_content"android:layout_height="0dp"android:layout_weight="0.5"><Buttonandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="0.5"android:text="New Button"android:id="@+id/button2" /><Buttonandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="0.5"android:text="New Button"android:id="@+id/button3" /></TableRow></TableLayout>
And here is how it looks like:
Post a Comment for "Android Tablelayout Remove Padding"