所以我有一个约束布局,高度为wrap_content
,宽度为match_parent
。我想知道Android约束布局 - 儿童对齐
如何对齐
button
到recycler view
的中心如果他们水平呈现。如何对齐
button
到LinearLayout
的中心(将在后面填充)..如果他们水平呈现。
我试图constraint.Guideline
但似乎不是因为约束布局wrap_content
高度的工作。有什么建议么?
所以我有一个约束布局,高度为wrap_content
,宽度为match_parent
。我想知道Android约束布局 - 儿童对齐
如何对齐button
到recycler view
的中心如果他们水平呈现。
如何对齐button
到LinearLayout
的中心(将在后面填充)..如果他们水平呈现。
我试图constraint.Guideline
但似乎不是因为约束布局wrap_content
高度的工作。有什么建议么?
也许对其他人这种解答可能有用。
我们可以在回收站视图或线性布局下有一个空视图。
<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"
这应该做的工作:)
要居中对齐,您需要设置左对齐和右对齐。例如
<Button
android:id="@+id/button"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
有你的第一个案件,但不是在第二(LinearLayout中),因此它具有固定的高度 –