【问题标题】:How to align items justified in android linear layout horizontal orientation?如何在android线性布局水平方向对齐项目?
【发布时间】:2015-12-01 23:06:27
【问题描述】:

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

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

谢谢

【问题讨论】:

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

标签: android android-layout alignment android-linearlayout


【解决方案1】:

你可以使用

android:layout_weight="1"

对于您的每个项目,这将解决您的问题并在屏幕中使用相等的空间排列项目

【讨论】:

    【解决方案2】:

    试试这个:

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

    【讨论】:

      【解决方案3】:

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

      喜欢这个:

      【讨论】:

        猜你喜欢
        • 2011-10-22
        • 2016-09-26
        • 1970-01-01
        • 2014-01-05
        • 2012-09-27
        • 1970-01-01
        • 1970-01-01
        • 2017-12-07
        • 1970-01-01
        相关资源
        最近更新 更多