如何在android线性布局水平方向对齐对齐项目?

如何在android线性布局水平方向对齐对齐项目?,android,android-layout,alignment,android-linearlayout,Android,Android Layout,Alignment,Android Linearlayout,我有5幅图像,它们应该以线性布局水平放置,并且应该以一种对齐的方式放置,第三幅图像位于屏幕的中心。所有图像的宽度和高度都相同 即图像之间的填充应动态调整 谢谢您可以使用 android:layout_weight=“1” 对于可以解决问题并在屏幕中使用相等空间排列项目的每个项目,请尝试以下操作: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.c

我有5幅图像,它们应该以线性布局水平放置,并且应该以一种对齐的方式放置,第三幅图像位于屏幕的中心。所有图像的宽度和高度都相同

即图像之间的填充应动态调整

谢谢

您可以使用

android:layout_weight=“1”

对于可以解决问题并在屏幕中使用相等空间排列项目的每个项目,请尝试以下操作:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#ff5678" />


    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#ff5678" />

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#ff5678" />

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#ff5678" />

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#ff5678" />
</LinearLayout>

每个
ImageView
添加空
View
和参数:
android:layout\u width=“0dp”
android:layout\u weight=“1”

您可以使用对齐中心并在子对象之间添加相同的边距

像这个:


在这种情况下,我建议您使用相对布局。