滚动我的RecyclerView
时,我想淡出我的FAB。这是我到目前为止所做的,但它没有按预期工作:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_wallpaper_tab1, container, false);
//FAB DISSOLVENZA
mFloatingActionButton = (FloatingActionButton) mFloatingActionButton.findViewById(R.id.fabWallpaperTab1);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0 && mFloatingActionButton.getVisibility() == View.VISIBLE) {
mFloatingActionButton.hide();
} else if (dy < 0 && mFloatingActionButton.getVisibility() != View.VISIBLE) {
mFloatingActionButton.show();
}
}
});
我的布局:
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerWallpaperTab1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
</android.support.v7.widget.RecyclerView/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabWallpaperTab1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:clickable="true"
app:backgroundTint="@color/textColorPrimary"
app:fabSize="normal"
app:srcCompat="@drawable/fab_upload" />
答案 0 :(得分:0)
使用:
mFloatingButton.setVisibility(View.INVISIBLE);
而不是mFloatingButton.hide();