【问题标题】:Changing a table row height更改表格行高
【发布时间】:2023-04-07 08:28:01
【问题描述】:

我正在开发一个具有平铺 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>

【问题讨论】:

    标签: android user-interface android-tablelayout shrink


    【解决方案1】:

    为什么不试试布局呢?

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

    【讨论】:

      【解决方案2】:
      // 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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-11-01
        • 2022-01-17
        • 2022-10-24
        • 1970-01-01
        • 1970-01-01
        • 2012-11-11
        相关资源
        最近更新 更多