gpt4 book ai didi

android - 使用 Android 的 ConstraintLayout 设置两个 View 之间的最大间距

转载 作者:行者123 更新时间:2023-12-04 14:18:42 25 4
gpt4 key购买 nike

我想知道在 Android 中是否有任何方法可以使用 ConstraintLayout 在使用 Chains 时设置两个 View 之间的最大间距。我知道使用 margin 属性就像两个 View 之间的最小间距一样,但我不知道如何设置最大间距。

例如,我如何通过以下布局 xml(最大间距 = 20dp)实现这一点?

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<View
android:id="@+id/left_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#FF0000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/right_view"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_chainStyle="spread" />

<View
android:id="@+id/right_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#00FF00"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/left_view"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />


</android.support.constraint.ConstraintLayout>

最佳答案

使用 <Space> 设置垂直或水平间距.关键是设置宽度或高度为0dp元素之间的最大空间,或固定间距的任何值(20dp):

<Space
android:layout_width="0dp"
android:layout_height="1dp"/>

关于android - 使用 Android 的 ConstraintLayout 设置两个 View 之间的最大间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57493308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com