0

我正在做一个具有平铺 UI 的应用程序。我有一个问题,因为我正在使用其中包含 2 个表格行的表格布局,但是,我需要将第一行缩小一点,但我已经尝试过使用填充和边距(android:paddingBottom 和 android:layout_marginBottom ) 但我不知道如何缩小第一行来做我想做的事。我附上了两张图片,更好地解释了我想要做什么,第一张是我在这里输入的代码得到的。第二个更好地解释了我想要做什么。

我必须做一个响应式 UI,所以我没想过使用固定的 android:layout_height。

这就是我所拥有的:

这就是我所拥有的

这就是我想要做的:

这就是我想做的

<?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>
4

2 回答 2

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>
于 2014-05-12T06:20:21.307 回答
0

为什么不尝试使用布局呢?

<?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>
于 2014-05-12T05:14:45.210 回答