【问题标题】:Fade FAB when scrolling in RecyclerView在 RecyclerView 中滚动时淡出 FAB
【发布时间】:2018-05-08 13:07:27
【问题描述】:

我想在我的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" />

【问题讨论】:

  • 您的问题究竟是什么?是你不能展示工厂还是隐藏它有问题??

标签: android android-fragments android-recyclerview floating-action-button


【解决方案1】:

用途:

mFloatingButton.setVisibility(View.INVISIBLE);

而不是mFloatingButton.hide();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    • 2016-03-09
    相关资源
    最近更新 更多