1

我正在寻找创建自动缩放的 2x2 行的最佳解决方案。到目前为止,我遇到的问题是左侧图像是全尺寸的,而右侧图像被缩小了很多。

图片为 400x400 像素,可能需要在所有设备上显示。

4

2 回答 2

2

TableLayout在您的 XML 布局文件中使用 Android 。

注意:GridView如果您的表中有可变数量的行,将是合适的。

2x2 示例

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <ImageView android:layout_weight="1"
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <ImageView android:layout_weight="1"
            android:id="@+id/imageView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </TableRow>
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <ImageView android:layout_weight="1"
            android:id="@+id/imageView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <ImageView android:layout_weight="1"
            android:id="@+id/imageView4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </TableRow>
</TableLayout>
于 2013-04-01T05:55:48.150 回答
0

在您的情况下, TableLayout可以正常工作,它保持固定数量的列,并且使用GridView您必须处理适配器和其他东西才能实现。

下面是一个使用 Imageview 创建 2x2 列的简单示例。

 <TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/button1"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:background="@drawable/ic_launcher"
            android:layout_height="wrap_content" />

        <ImageView
            android:id="@+id/button2"
            android:layout_weight="1"
            android:layout_width="fill_parent"
              android:background="@drawable/ic_launcher"
            android:layout_height="wrap_content" />
    </TableRow>


</TableLayout>
于 2013-04-01T06:07:09.933 回答