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

时间:2015-09-06 07:05:23

标签: android android-layout alignment android-linearlayout

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

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

由于

3 个答案:

答案 0 :(得分:4)

您可以使用

机器人:layout_weight = “1”

为您的每个项目解决您的问题并使用相同的空间在屏幕上排列项目

答案 1 :(得分:3)

试试这个:

<?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>

Beetwen每个ImageView添加空View个参数:android:layout_width="0dp" android:layout_weight="1"

答案 2 :(得分:1)

您可以使用JustifyLayout对齐中心并在孩子中添加相同的边距。

喜欢这个:

enter image description here

相关问题