How can I add the new “Floating Action Button” between two widgets/layouts

前端 未结 10 2015
离开以前
离开以前 2020-11-22 10:31

I guess you have seen the new Android design guidelines, with the new \"Floating Action Button\" a.k.a \"FAB\"

For instance this pink button:

相关标签:
10条回答
  • 2020-11-22 10:56

    Now it is part of official Design Support Library.

    In your gradle:

    compile 'com.android.support:design:22.2.0'
    

    http://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html

    0 讨论(0)
  • 2020-11-22 10:58

    Try this library (javadoc is here), min API level is 7:

    dependencies {
        compile 'com.shamanland:fab:0.0.8'
    }
    

    It provides single widget with ability to customize it via Theme, xml or java-code.

    light between

    It's very simple to use. There are available normal and mini implementation according to Promoted Actions pattern.

    <com.shamanland.fab.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_action_my"
        app:floatingActionButtonColor="@color/my_fab_color"
        app:floatingActionButtonSize="mini"
        />
    

    Try to compile the demo app. There is exhaustive example: light and dark themes, using with ListView, align between two Views.

    0 讨论(0)
  • 2020-11-22 10:58

    Here is one aditional free Floating Action Button library for Android. It has many customizations and requires SDK version 9 and higher

    enter image description here

    Full Demo Video

    dependencies {
        compile 'com.scalified:fab:1.1.2'
    }
    
    0 讨论(0)
  • 2020-11-22 11:00

    Seems like the cleanest way in this example is to:

    • Use a RelativeLayout
    • Position the 2 adjacent views one below the other
    • Align the FAB to the parent right/end and add a right/end margin
    • Align the FAB to the bottom of the header view and add a negative margin, half the size of the FAB including shadow

    Example adapted from shamanland implementation, use whatever FAB you wish. Assume FAB is 64dp high including shadow:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <View
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="120dp"
        />
    
        <View
            android:id="@+id/body"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/header"
        />
    
        <fully.qualified.name.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignBottom="@id/header"
            android:layout_marginBottom="-32dp"
            android:layout_marginRight="20dp"
        />
    
    </RelativeLayout>
    

    FAB Layout example

    0 讨论(0)
提交回复
热议问题