我在RelativeLayout中有两个FAB,然后在另一个RelativeLayout中添加了它们。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="60dp"
android:visibility="invisible">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
app:backgroundTint="@color/colorPrimary"
app:fabSize="mini"
app:srcCompat="@drawable/ic_image_black_24dp"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabPosition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:layout_alignParentBottom="true"
android:layout_toEndOf="@id/fabImage"
android:layout_toRightOf="@id/fabImage"
android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"
app:backgroundTint="@color/colorPrimary"
app:fabSize="mini"
app:srcCompat="@drawable/ic_gps_fixed_black_24dp"/>
为了显示两个FAB,我使用主FAB中的动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
android:duration="2000"
android:fromXScale="0.3"
android:toXScale="1.0"
android:fromYScale="0.3"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%" />
虽然FAB使用“动画”按比例放大,但它们位于布局的下方(被覆盖),因此其底部不可见。
这是父级RelativeLayout,其中包含主FAB:
<RelativeLayout
android:id="@+id/parent_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/SendButton"
android:layout_toLeftOf="@id/SendButton"
android:layout_toStartOf="@id/SendButton">
...
<android.support.design.widget.FloatingActionButton
android:id="@+id/FabButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:backgroundTint="@android:color/transparent"
app:elevation="0dp"
app:borderWidth="0dp"
app:srcCompat="@drawable/ic_add_circle_black_24dp"
app:fabCustomSize="48dp"/>
...
</RelativeLayout>
这是添加视图的代码:
RelativeLayout relativeLayout = (RelativeLayout) rootView.findViewById(R.id.parent_layout);
View fabView = getLayoutInflater().inflate(R.layout.fab, null);
relativeLayout.addView(fabView);
要解决此问题,我在右边的FAB上使用了marginRight,但对于底部它不起作用。我该如何解决?