【发布时间】:2019-08-14 19:36:54
【问题描述】:
我想知道是否有任何方法可以在 Android 中使用 ConstraintLayout 在使用 Chains 时设置两个视图之间的最大间距。我知道使用margin 属性就像两个视图之间的最小间距一样,但我不知道如何设置最大间距。
例如,我如何通过以下布局 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>
【问题讨论】:
-
请说明您希望达到的目标
-
你可以使用
packed chain并给margins它对于所有屏幕尺寸都是恒定的..
标签: android android-constraintlayout constraint-layout-chains