如何将浮动操作按钮对齐到中心 [英] How to align Floating Action Button to center

查看:58
本文介绍了如何将浮动操作按钮对齐到中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个FloatingActionButton.我希望它位于2 LinearLayouts的中间并且像这样位于屏幕的中心.

I have one FloatingActionButton. I want it to be middle of 2 LinearLayouts and center of screen like this.

当前我的设计就是这样

我希望它位于屏幕的确切中心.该怎么做?

I want it to be at the exact center of the screen. How to do that?

这是我的整个xml代码

This is my whole xml code

<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">
<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout
        android:id="@+id/viewA"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.6"
        android:orientation="horizontal"/>
    <LinearLayout
        android:id="@+id/viewB"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.2"
        android:orientation="horizontal"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:src="@drawable/ic_plus"
    app:layout_anchor="@id/viewA"
    android:layout_centerHorizontal="true"
    app:layout_anchorGravity="bottom"
    android:layout_centerInParent="true" />

推荐答案

您的 CoordinatorLayout FrameLayout,所以尝试这种方式, 希望对您有帮助.

Your CoordinatorLayout is a FrameLayout , So try this way, I hope it will helps you .

 app:layout_anchorGravity="bottom|center"

这篇关于如何将浮动操作按钮对齐到中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆