所以我有一个高度为wrap_content
和宽度为match_parent
的约束布局。我想知道
如果button
水平渲染,recycler view
与button
的中心对齐。
如何将LinearLayout
与constraint.Guideline
的中心对齐(稍后将填充)..如果它们是水平渲染的。
我尝试了wrap_content
,但由于约束布局{{1}}高度,它似乎无效。有什么建议吗?
答案 0 :(得分:0)
要居中对齐,您需要相对于父级设置左右对齐。 e.g。
<Button
android:id="@+id/button"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
答案 1 :(得分:0)
对于其他人来说,这个答案可能很有用。
我们可以在回收者视图或线性布局下面看到一个空视图。
<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"
这应该做的工作:)