3
我目前正在使用设计支持库。我试着用我的CoordinatorLayout来实现Snackbar,它包装整个布局。当要显示Snackbar时,它会引发FAB。但它没有努力下降,从而保持在翻译的距离之上。如何正确实施Snackbar,协调员布局和底部FAB?
但是,当我通过滑动Snackbar而忽略它时,它会下降。所以CoordinatorLayout知道里面包裹着FAB。
的.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();
没有运气。案件依然如此。 –
@AchillesRasquinha我认为这将有助于https://lab.getbase.com/introduction-to-coordinator-layout-on-android/ – Wizard
是的。我已经检查过他们。包括文档。但没有运气。 –