2017-09-14 117 views
0

所以我有一個約束佈局,高度爲wrap_content,寬度爲match_parent。我想知道Android約束佈局 - 兒童對齊

  1. 如何對齊buttonrecycler view中心如果他們水平呈現。

  2. 如何對齊buttonLinearLayout中心(將在後面填充)..如果他們水平呈現。

我試圖constraint.Guideline但似乎不是因爲約束佈局wrap_content高度的工作。有什麼建議麼?

+0

有你的第一個案件,但不是在第二(LinearLayout中),因此它具有固定的高度 –

回答

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" 

這應該做的工作:)

0

要居中對齊,您需要設置左對齊和右對齊。例如

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