将视图底部与ConstraintLayout中心对齐

3
我有一个自定义视图,我想将其放置在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"

但是正如我所说的,我希望将视图底部与ConstraintLayout的中心对齐。

有没有好的方法来实现这一点?


您可以通过将准线保持在50%的位置,然后将视图底部与准线顶部对齐来使用中心线指南。 - Burhanuddin Rashid
1个回答

6
您可以使用Guideline来为您的布局添加额外的约束条件,例如:
<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"/>

然后对齐您的视图,如下所示:

    app:layout_constraintBottom_toTopOf="@+id/guideline"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接