Mag*_*s W 3 android android-layout android-view android-constraintlayout
我有一个自定义视图,我想将它放在 a 中ConstraintLayout,使其底部位于ConstraintLayout.
子视图具有动态高度wrap_content,因此我无法轻松设置固定边距或填充。
我知道我可以将视图的中心与ConstraintLayout使用的中心对齐
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Run Code Online (Sandbox Code Playgroud)
但正如我所说,我想将视图的底部与ConstraintLayout.
有什么好的方法来实现这一点吗?
您可以使用 aGuideline为您的布局添加额外的约束,如下所示:
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5"/>
Run Code Online (Sandbox Code Playgroud)
,然后将您的视图与此指南对齐,如下所示:
app:layout_constraintBottom_toTopOf="@+id/guideline"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3734 次 |
| 最近记录: |