Search code examples
javaandroidtablerowandroid-tablelayout

How to change TableRow height in Android?


I want to customize TableRow in my app - change it's height in order i can place two rows of buttons in it. I can't implement it in UI designer. So the question - how can I do this programmaticaly in XML or Java code?


Solution

  • Not exactly sure what you are wanting, but here is how you can get "rows" of Buttons in one TableRow. Do something similar to this and see if that is what you are talking about.

    I added a LinearLayout to the TableRow that is vertical orientation and then wrapper the Buttons in another LinearLayout that is horizontal orientation.

    <TableRow>
    
        <LinearLayout
            android:id="@+id/layout3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
    
            <LinearLayout
                android:id="@+id/layout1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >
    
                <Button
                    android:id="@+id/button1"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="ABCDE" />
    
                <Button
                    android:id="@+id/button2"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="A" />
    
                <Button
                    android:id="@+id/button3"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="ABC" />
            </LinearLayout>
    
            <LinearLayout
                android:id="@+id/layout2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >
    
                <Button
                    android:id="@+id/button1"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="ABCDE" />
    
                <Button
                    android:id="@+id/button2"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="A" />
    
                <Button
                    android:id="@+id/button3"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="ABC" />
            </LinearLayout>
        </LinearLayout>
    </TableRow>