Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

android - Moving Floating Action Button up and down to avoid getting blocked by a snackbar

I'm using this library to implement a floating action bar and I can't seem to find a way to move the button when a snackbar appears on screen. Is it even possible with that library?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To anyone looking out for answer in future..

Coordinator Layout used as Parent Layout of Floating Action Button will handle the animation effect for you automatically.

The floating action button has a default behavior that detects Snackbar views being added and animates the button above the height of the Snackbar accordingly.

Floating Action Button Behavior

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/clayout">
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_marginBottom="16dp"
    android:layout_marginRight="16dp"
    android:src="@drawable/filter_icon"
    app:rippleColor="@color/colorGray"
    app:fabSize="normal"
    app:borderWidth="0dp"/>
</android.support.design.widget.CoordinatorLayout>

Then our SnackBar code would use Coordinatorlayout[here clayout] as parentlayout like below:

Snackbar.make(clayout, "Click on row to know more details", Snackbar.LENGTH_LONG)
                    .setAction("OK", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                        }
                    }).show();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...