Android 4 张图片的工作室布局
Android Studio Layout for 4 images
我在 xml 中布置 activity 布局时遇到一些问题,我正在使用“设计”选项,布局如下面的 xml 所示,全部嵌入到一个RelativeLayout中。
基本上,我想要的是四个均匀的 ImageView,我也会为测验添加图像,并且有 4 个正方形,两个在顶部,两个在底部,它们加起来会形成一个更大的正方形。
我有的没问题,但我认为应该有更好的或标准的方式,或者用 Android?
来布置这样的东西
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:maxWidth="100dp"
android:maxHeight="100dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:nestedScrollingEnabled="false"
android:layout_toStartOf="@+id/imageView2"
android:layout_alignTop="@+id/imageView2"
android:layout_toLeftOf="@+id/imageView2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:maxWidth="100dp"
android:maxHeight="100dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:nestedScrollingEnabled="false"
android:layout_marginTop="94dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="89dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView3"
android:maxWidth="100dp"
android:maxHeight="100dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:nestedScrollingEnabled="false"
android:layout_below="@+id/imageView2"
android:layout_alignLeft="@+id/imageView2"
android:layout_alignStart="@+id/imageView2"
android:layout_alignRight="@+id/imageView2"
android:layout_alignEnd="@+id/imageView2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView4"
android:maxWidth="100dp"
android:maxHeight="100dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:nestedScrollingEnabled="false"
android:layout_below="@+id/imageView"
android:layout_alignLeft="@+id/imageView"
android:layout_alignStart="@+id/imageView" />
您可以使用 GridView
作为图像的布局,我认为您可以使用 layout_weight
和 weightSum
来避免必须为图像设置明确的大小和担心关于它不能在不同的屏幕尺寸上正常工作。这和图像重叠的担忧。
Here's an SO question that covers using a two column gridview for images as well, I'm not sure if this would help you either but since you said two images on top and two on bottom this might still be useful in a way. You can refer to this SO question and the marked answer for a better explanation on what layout_weight
does and here's a reference for weightSum
。
我已经通过使用 LinearLayouts 解决了这个问题,每个 LinearLayouts 都有 2 个 ImageView,嵌套在实际表单的父 LinearLayout 中。父 LinearLayout 具有 orientation="vertical" 和嵌套的 LinearLayout="horizontal".
我在 xml 中布置 activity 布局时遇到一些问题,我正在使用“设计”选项,布局如下面的 xml 所示,全部嵌入到一个RelativeLayout中。
基本上,我想要的是四个均匀的 ImageView,我也会为测验添加图像,并且有 4 个正方形,两个在顶部,两个在底部,它们加起来会形成一个更大的正方形。
我有的没问题,但我认为应该有更好的或标准的方式,或者用 Android?
来布置这样的东西<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:maxWidth="100dp"
android:maxHeight="100dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:nestedScrollingEnabled="false"
android:layout_toStartOf="@+id/imageView2"
android:layout_alignTop="@+id/imageView2"
android:layout_toLeftOf="@+id/imageView2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:maxWidth="100dp"
android:maxHeight="100dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:nestedScrollingEnabled="false"
android:layout_marginTop="94dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="89dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView3"
android:maxWidth="100dp"
android:maxHeight="100dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:nestedScrollingEnabled="false"
android:layout_below="@+id/imageView2"
android:layout_alignLeft="@+id/imageView2"
android:layout_alignStart="@+id/imageView2"
android:layout_alignRight="@+id/imageView2"
android:layout_alignEnd="@+id/imageView2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView4"
android:maxWidth="100dp"
android:maxHeight="100dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:nestedScrollingEnabled="false"
android:layout_below="@+id/imageView"
android:layout_alignLeft="@+id/imageView"
android:layout_alignStart="@+id/imageView" />
您可以使用 GridView
作为图像的布局,我认为您可以使用 layout_weight
和 weightSum
来避免必须为图像设置明确的大小和担心关于它不能在不同的屏幕尺寸上正常工作。这和图像重叠的担忧。
Here's an SO question that covers using a two column gridview for images as well, I'm not sure if this would help you either but since you said two images on top and two on bottom this might still be useful in a way. You can refer to this SO question and the marked answer for a better explanation on what layout_weight
does and here's a reference for weightSum
。
我已经通过使用 LinearLayouts 解决了这个问题,每个 LinearLayouts 都有 2 个 ImageView,嵌套在实际表单的父 LinearLayout 中。父 LinearLayout 具有 orientation="vertical" 和嵌套的 LinearLayout="horizontal".