如何对齐以Android线性布局水平方向对齐的项目?

hyb*_*rid 5 android alignment android-layout android-linearlayout

我有5张图像,它们应该以线性布局水平放置,并且应该以合理的方式放置,第3张图像位于屏幕中央。所有图像具有相同的宽度和高度。

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

谢谢

小智 6

您可以使用

android:layout_weight =“ 1”

为您的每个商品解决问题,并在屏幕中使用相等的空间排列商品


die*_*r_h 5

尝试这个:

<?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>
Run Code Online (Sandbox Code Playgroud)

Beetwen每一个都用参数ImageView添加空Viewandroid:layout_width="0dp" android:layout_weight="1"