How to implement Snackbar, Layout coordinator and lower right FAB?

I am currently using the design support library. I tried implementing Snackbar with my Layout coordinator shaking the entire layout. When the Snackbar is displayed, it calls FAB. But he makes no effort to go down and thereby remain above the translated distance.

However, this happens when I fire Snackbar while reading it. Therefore, the Layout coordinator knows about the FAB enclosed inside.

.xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/relative_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/primary"
            android:elevation="4dp"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

        <com.google.android.gms.ads.AdView
            android:id="@+id/ad_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/toolbar"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center_horizontal"
            ads:adSize="BANNER"
            ads:adUnitId="@string/banner_ad_unit_id" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/ad_view">

            <include layout="@layout/card_view" />

        </ScrollView>

    </RelativeLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/btn_generate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right|end"
        android:layout_margin="16dp"
        android:src="@drawable/ic_refresh_white_24dp"
        app:elevation="6dp"
        app:fabSize="normal"
        app:pressedTranslationZ="12dp" />

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

.java

Snackbar.make(mCoordinatorLayout, R.string.copied_to_clipboard,
                Snackbar.LENGTH_SHORT).show(); 
+4
source share
2 answers

Snackbar , , CoordinatorLayout ,

findViewById(R.id.btn_generate).setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        Snackbar.make(view, "Hello Snackbar", Snackbar.LENGTH_LONG).show();
      }
});
+4

, . , . ; ;-)!

Snackbar.make(findViewById(android.R.id.content),"Your text",Snackbar.LENGTH_SHORT).show();

, show(), .

0

Source: https://habr.com/ru/post/1618622/


All Articles