I'd like to add Floating Action Button between the two layouts.

Asked 2 years ago, Updated 2 years ago, 113 views

There's a floating action button called FAB that's newly added to Android.

1

I'd like a pink button here. My question is, I've tried many things, but I don't know how to add FAB between the two layouts like the picture above. Please tell me how to do it.

android floating-action-button

2022-09-21 20:22

1 Answers

First of all, build.gradle has 'com'.Add android.support:design:23.1.1'.

2

<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="match_parent"
            android:layout_weight="0.6"
            android:background="@android:color/holo_purple"
            android:orientation="horizontal"/>

        <LinearLayout
            android:id="@+id/viewB"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.4"
            android:background="@android:color/holo_orange_light"
            android:orientation="horizontal"/>

    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@drawable/ic_done"
        app:layout_anchor="@id/viewA"
        app:layout_anchorGravity="bottom|right|end"/>

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

You can copy this.


2022-09-21 20:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.