浮动动作按钮重叠一个

时间:2017-11-01 01:24:29

标签: android android-layout android-fragments

我正在尝试在我的应用程序中创建浮动操作按钮,我添加了两个浮动操作按钮,但问题是它们出现在彼此之上。   我正在使用碎片,它的碎片是否重要?有人可以指出我在做什么错。我正在使用协调器布局,我正在使用相对布局。在它的最后我使用浮动动作按钮。这是代码段

<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">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainFragment"
tools:context="com.saibaba.myapplication.MainFragment">


<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/bg1"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true" /> 


  </RelativeLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_share"
    android:layout_width="352dp"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin_right"
    android:layout_marginBottom="100dp"
    android:src="@drawable/ic_action_share"
    app:elevation="8dp"
    app:layout_anchor="@id/mainFragment"
    app:layout_anchorGravity="bottom|end"
    app:pressedTranslationZ="12dp" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_plus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin_right"
    android:layout_marginBottom="16dp"
    android:src="@drawable/ic_action_plus"
    app:backgroundTint="#FF0000"
    app:borderWidth="0dp"
    app:elevation="8dp"
    app:layout_anchor="@id/mainFragment"
    app:layout_anchorGravity="bottom|right|end"
    app:pressedTranslationZ="12dp" />



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

1 个答案:

答案 0 :(得分:0)

当您在代码中设置android:layout_margin时,其他android:layout_marginBottomandroid:layout_marginLeftandroid:layout_marginRightandroid:layout_marginTop将无法生效。

删除

android:layout_margin="@dimen/fab_margin_right"