微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android – 将视图中心与其他视图的底部对齐

一张图片讲述的不仅仅是冗长的演讲:

enter image description here


我想垂直对齐红色部分的中心和黑色部分的中间.我没有容器的约束(RelativeLayout,FrameLayout,LinearLayout oO).

我尝试了一个高度为0dp的视图与黑色视图的底部对齐,并将红色视图的alignBaseline对齐,但它不起作用…

谢谢你的帮助 !

解决方法:

Android现在支持CoordinatorLayout的布局锚点:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <View android:id="@+id/black_view"
        android:layout_width="match_parent" android:layout_height="@dimen/black_height"/>

    <View android:id="@+id/red_view"
        android:layout_width="@dimen/red_width" android:layout_height="@dimen/red_height"
        app:layout_anchor="@id/black_view" app:layout_anchorGravity="bottom|center"/>

</android.support.design.widget.CoordinatorLayout>

如果更改Java代码中视图的大小,则锚也将保持不变.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐