首页 > 解决方案 > 最后一项左对齐

问题描述

我正在使用 Google 的官方 Flexbox 实现来对齐正方形,我想知道是否可以将最后一项对齐到左侧。我尝试使用 app:justifyContent="flex_start" 但它并不适合所有屏幕,例如 app:justifyContent="space_between"。我搜索但一无所获。你能帮助我吗?这是屏幕的图像,这是代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:background="@color/white"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/constraint_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.flexbox.FlexboxLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:justifyContent="space_between"
            app:flexWrap="wrap"
            android:layout_margin="4dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <ImageView
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:background="@color/colorPrimary"
                android:layout_margin="4dp"/>

            <ImageView
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:background="@color/colorPrimary"
                android:layout_margin="4dp"/>

            <ImageView
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:background="@color/colorPrimary"
                android:layout_margin="4dp"/>

            <ImageView
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:background="@color/colorPrimary"
                android:layout_margin="4dp"/>

            <ImageView
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:background="@color/colorPrimary"
                android:layout_margin="4dp"/>

            <ImageView
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:background="@color/colorPrimary"
                android:layout_margin="4dp"/>

            <ImageView
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:background="@color/colorPrimary"
                android:layout_margin="4dp"/>

            <ImageView
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:background="@color/colorPrimary"
                android:layout_margin="4dp"/>

            <ImageView
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:background="@color/colorPrimary"
                android:layout_margin="4dp"/>

            <ImageView
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:background="@color/colorPrimary"
                android:layout_margin="4dp"/>

            <ImageView
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:background="@color/colorPrimary"
                android:layout_margin="4dp"/>

        </com.google.android.flexbox.FlexboxLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

标签: androidandroid-studio

解决方案


推荐阅读