Java Android 2x2行自动缩放的图像

Java Android 2x2行自动缩放的图像,java,android,Java,Android,我正在寻找最佳的解决方案,以创建2x2行自动缩放。到目前为止,我面临的问题是,左边的图片是全尺寸的,右边的图片被缩小了很多 图片将为400x400像素,可能需要在所有设备上显示。在XML布局文件中使用AndroidTableLayout 注意:GridView适用于表中行数可变的情况 2x2示例: <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" >

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


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

在XML布局文件中使用Android
TableLayout

注意:
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>

在您的情况下会很好地工作,它保持固定的列数,并且您必须处理适配器和其他东西才能实现

下面是一个使用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>


它与@drawable/ic_launcher一起工作,因为ic_launcher的尺寸很小,但是如果我们在这些Imageview中放置两个大小不同的图像,那么它只会显示“android:id=“@+id/button2”“ImageView image.layout_如果给定了权重,它将自动均衡缩放。是的,你是对的,但我尝试了使用两个不同大小的图像,一个是900 x 1440,另一个是338 x 450大小。它只显示大图像。我们应该使用LayoutParams来处理这个问题。我使用LinearLayout和ImageView创建了一个2 x 2演示。从这个链接下载:我想它可能会对你有所帮助。我正在创建这个示例演示代码。高度不可缩放。我试过android:layout\u height=“fill\u parent”,但不起作用。