Android layout 使用线性布局android在一个视图中显示4幅图像
我希望使用Android layout 使用线性布局android在一个视图中显示4幅图像,android-layout,Android Layout,我希望使用LinearLayout制作2乘2的图像,使您的权重相等。有人能帮我吗?谢谢。谢谢你的帮助 我正在尝试让我的Android应用程序的xml工作,但我有一些问题。我试图以线性布局并排显示大小相等的2幅图像。它们之间必须有一个边距,在左右两侧和顶部 我的代码只能给我3张图像,但我需要4张图像。 我很感激能帮我解决这个问题 这是我的代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
LinearLayout
制作2乘2的图像,使您的权重相等。有人能帮我吗?谢谢。谢谢你的帮助
我正在尝试让我的Android应用程序的xml工作,但我有一些问题。我试图以线性布局并排显示大小相等的2幅图像。它们之间必须有一个边距,在左右两侧和顶部
我的代码只能给我3张图像,但我需要4张图像。
我很感激能帮我解决这个问题
这是我的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horiztontal"
android:weightSum="2">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:weightSum="2">
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:weightSum="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView3"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
使用以下布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:layout_margin="10dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
<ImageView
android:layout_margin="10dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:layout_margin="10dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
<ImageView
android:layout_margin="10dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
注意:您还可以使用相对布局或约束布局优化此布局。使用代码平均分割4个图像
Use the Code split 4 images equally
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linear1"
android:orientation="horizontal"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:id="@+id/imageview"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:id="@+id/imageview1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linear2"
android:orientation="horizontal"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:id="@+id/imageview3"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:id="@+id/imageview14"/>
</LinearLayout>
每个图像视图都将Scaletype属性设置为FitXY