Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Android';这是你的梦想_Android_Android Constraintlayout_Constraint Layout Chains - Fatal编程技术网

使用Android';这是你的梦想

使用Android';这是你的梦想,android,android-constraintlayout,constraint-layout-chains,Android,Android Constraintlayout,Constraint Layout Chains,我想知道,在Android中,使用ConstraintLayout时,是否有任何方法可以设置两个视图之间的最大间距(当使用链时)。我知道使用margin属性就像两个视图之间的最小间距一样,但我不知道如何设置最大间距 例如,如何通过以下布局xml(最大间距=20dp)实现这一点 如果要设置自定义间距(最大20dp),则应使用以下选项: app:layout\u constraintal\u chainStyle=“packed” 然后,可以使用边距在视图之间添加间距,使其成为视图之间的最大间距

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

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


如果要设置自定义间距(最大20dp),则应使用以下选项:

app:layout\u constraintal\u chainStyle=“packed”
然后,可以使用边距在视图之间添加间距,使其成为视图之间的最大间距


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



请解释您希望实现的目标您可以使用
包装链
并提供
边距
它对于所有屏幕大小都是恒定的..谢谢您的回复,@BirjuVachhani:)。在您的示例中,20dp设置的最大间距在哪里?非常感谢您的编辑。但现在我有了第二个问题:如果屏幕太小以至于20dp的间距太大怎么办?使用你的解决方案,间距将固定为20dp,不允许低于20dp。谢谢你提出的另一个奇怪的问题。1) 我不认为现在有太多的小屏幕在使用(除非你正在使用android wear!!)。2) 我不认为你问的是可能的。不过,一个你试图实现的形象会很有帮助。@AugustoCarmo:如果你不想硬编码20dp。最好的方法是保存在dimen的文件中,然后根据分辨率、屏幕宽度(sw)等创建不同的dimen。检查此链接:
<?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
    android:layout_width="0dp"
    android:layout_height="1dp"/>