Android约束布局-儿童对齐 [英] Android Constraint Layout - Alignment of childrens

查看:59
本文介绍了Android约束布局-儿童对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个约束布局,高度为 wrap_content ,宽度为 match_parent .我想知道

So I have a constraint layout with height wrap_content and width match_parent. I would like to know

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

  1. How to align a button to the centre of a recycler view if they are rendered horizontally.

如何将按钮 LinearLayout (稍后将填充)的中心对齐.水平渲染.

How to align a button to the centre of a LinearLayout(which will be populated later).. if they are rendered horizontally.

我尝试了 constraint.Guideline ,但是由于约束布局 wrap_content 的高度,它似乎不起作用.有什么建议吗?

I tried constraint.Guideline but it seems not working because of constraint layout wrap_content height. any suggestions?

推荐答案

也许对于其他人来说,这个答案可能是有用的.

Maybe for other people this answer can be useful.

在回收站视图或线性布局下面,我们可以有一个空白视图.

We can have an empty view below recycler view or linear layout.

<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" />

现在将按钮对齐到父顶部和该视图的中心.

now align button to the centre of parent top and this view.

app:layout_constraintBottom_toTopOf="@+id/horizontal_view"
app:layout_constraintLeft_toLeftOf="@+id/parent"
app:layout_constraintRight_toLeftOf="recyclerview"
app:layout_constraintTop_toTopOf="parent"

这应该可以完成工作:)

This should do the work :)

这篇关于Android约束布局-儿童对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆