当工具栏隐藏布局抖动而滚动RecyclerView [英] Layout Jitter when Toolbar hides while scrolling RecyclerView

查看:1164
本文介绍了当工具栏隐藏布局抖动而滚动RecyclerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工具栏,PageSlidingTab和ViewPager布局。里面ViewPager存在与RecyclerView的片段。我想隐藏工具栏,因为我滚动RecyclerView。我已经加入以下code ++实现的:

Hi , I have a layout with Toolbar, PageSlidingTab and ViewPager. Inside ViewPager there is a fragment with RecyclerView. I want to hide the Toolbar as i scroll the RecyclerView. I have achieved it by adding the following code :

 toolbar  = ((MyActivity)getActivity()).getToolbar();

    mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        int toolbarMarginOffset = 0;

        private int dp(int inPixels){
            return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, inPixels, getActivity().getResources().getDisplayMetrics());
        }



        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);


        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            toolbarMarginOffset += dy;
            if(toolbarMarginOffset>dp(56)){

                toolbarMarginOffset = dp(56);

            }

            if(toolbarMarginOffset<0){

                toolbarMarginOffset = 0;

            }


            ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)toolbar.getLayoutParams();

            params.topMargin = -1*toolbarMarginOffset;

            toolbar.setLayoutParams(params);


        }
    });

按预期正常工作,但同时滚动出现在工具栏隐藏(如图片所示)闪烁。我知道,因为布局调整大小的事情发生。我怎样才能解决这个问题?请提出一个很好的解决了这一点。

It works fine as expected but while scrolling there is a flicker when the toolbar is hiding (As shown in image). I know its happening because of Layout resize. How can i fix this issue? Please suggest a good solution to this.

推荐答案

我有同样的问题。我使用这个库 Android的ObservableScrollView

I had the same problem. I solved the problem using this library Android-ObservableScrollView

这篇关于当工具栏隐藏布局抖动而滚动RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆