Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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_Constraints - Fatal编程技术网

Android约束布局-儿童对齐

Android约束布局-儿童对齐,android,constraints,Android,Constraints,因此,我有一个约束布局,高度wrap\u content和宽度match\u parent。我想知道 如何将按钮与回收器视图的中心对齐(如果它们是水平渲染的) 如何将按钮与线性布局的中心对齐(稍后将填充)。。如果它们是水平渲染的 我尝试了constraint.Guideline,但由于约束布局wrap\u内容高度,它似乎不起作用。有什么建议吗?要居中对齐,需要设置相对于父对象的左对齐和右对齐。e、 g <Button android:id="@+id/button" app

因此,我有一个约束布局,高度
wrap\u content
和宽度
match\u parent
。我想知道

  • 如何将
    按钮
    回收器视图
    中心对齐(如果它们是水平渲染的)

  • 如何将
    按钮
    线性布局
    中心对齐(稍后将填充)。。如果它们是水平渲染的


  • 我尝试了
    constraint.Guideline
    ,但由于约束布局
    wrap\u内容
    高度,它似乎不起作用。有什么建议吗?

    要居中对齐,需要设置相对于父对象的左对齐和右对齐。e、 g

    <Button
        android:id="@+id/button"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>
    

    也许这个答案对其他人有用

    我们可以在回收器视图或线性布局下方有一个空视图

    <View
            android:id="@+id/horizontal_view"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/recyclerview"
            tools:layout_editor_absoluteX="8dp" />
    

    这应该可以完成以下工作:)

    得到第一种情况的结果,但在第二种情况下没有结果(线性布局),它有固定的高度
    app:layout_constraintBottom_toTopOf="@+id/horizontal_view"
    app:layout_constraintLeft_toLeftOf="@+id/parent"
    app:layout_constraintRight_toLeftOf="recyclerview"
    app:layout_constraintTop_toTopOf="parent"