0

I'm doing an app that have a tiled UI. I have a problem because I'm using an table layout with 2 table rows inside of it, but, I need to shrink the first row a little bit but I've already tried using padding and margins (android:paddingBottom & android:layout_marginBottom) but I don't get how to shrink the first row to do what I want to do. I attached 2 images that explain better what I want to do, the first one is what I got with the code that I put in here. The second explains better what I want to do.

I have to do a responsive UI so I nor thought to use a fixed android:layout_height.

This is what I have:

This is what I have

This is what I want to do:

This is what I want to do

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="2dp"
            android:layout_weight="1"
            android:background="@drawable/camera"
            android:gravity="top|center_horizontal"
            android:onClick="camera" />

        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="2dp"
            android:layout_weight="1"
            android:background="@drawable/gallery"
            android:gravity="top|center_horizontal"
            android:onClick="gallery" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <Button
            android:id="@+id/button3"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="2dp"
            android:layout_weight="1"
            android:background="@drawable/bank_bbva"
            android:gravity="top" />
    </TableRow>
</TableLayout>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

0

Why not to try this with layouts?

<?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="vertical" >

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

<Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_margin="2dp"
        android:layout_weight="0.5"
        android:background="@drawable/camera"
        android:gravity="top|center_horizontal"
        android:onClick="camera" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_margin="2dp"
        android:layout_weight="0.5"
        android:background="@drawable/gallery"
        android:gravity="top|center_horizontal"
        android:onClick="gallery" />
</LinearLayout>

<Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_margin="2dp"
        android:layout_weight="1"
        android:background="@drawable/bank_bbva"
        android:gravity="top" />

</LinearLayout>
Javanshir
  • 772
  • 2
  • 7
  • 20
0
// try this way,hope this will help you...

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp">

        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/camera"
            android:onClick="camera" />

        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:background="@drawable/gallery"
            android:onClick="gallery" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/button3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bank_bbva"/>
    </TableRow>
</TableLayout>
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67