Android约束布局-儿童对齐 [英] Android Constraint Layout - Alignment of childrens
问题描述
所以我有一个约束布局,高度为 wrap_content
,宽度为 match_parent
.我想知道
So I have a constraint layout with height wrap_content
and width match_parent
. I would like to know
-
如何将
按钮
与回收站视图
的中心对齐(如果它们是水平渲染的话).
How to align a
button
to the centre of arecycler 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屋!