滚动向下时,Android listView onScroll口吃动画

时间:2015-03-26 08:31:28

标签: android listview scroll

所以现在当我向下滚动它时隐藏工具栏和浮动底部,直到我到达下一个视图项顶部的边缘。所有隐藏的东西都出现了一个毫秒,然后又回到隐藏状态,即使我只是向下滚动。

有什么建议吗?

mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
        private int mLastFirstVisibleItem;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                             int visibleItemCount, int totalItemCount) {
            Animation fadeIn = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.fade_in);
            Animation fadeOut = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.fade_out);

        if(mLastFirstVisibleItem != firstVisibleItem) {
            if (mLastFirstVisibleItem < firstVisibleItem) {

                bottomBar.startAnimation(fadeOut);
                bottomBar.setVisibility(View.GONE);

                fab.startAnimation(fadeOut);
                fab.hide(true);

            }
            else {
                bottomBar.startAnimation(fadeIn);
                bottomBar.setVisibility(View.VISIBLE);

                fab.startAnimation(fadeIn);
                fab.show(true);

            }
        }
            mLastFirstVisibleItem = firstVisibleItem;

        }
    });

1 个答案:

答案 0 :(得分:0)

嘿,尝试这样的事情:

final Animation fadeIn = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.fade_in);
final Animation fadeOut = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.fade_out);
        listViewRight.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

                if(mLastFirstVisibleItem != firstVisibleItem) {
                    if (mLastFirstVisibleItem < firstVisibleItem && (bottomBar.getVisibility() == View.VISIBLE)) {

                        fadeOut.setAnimationListener(new Animation.AnimationListener() {
                            @Override
                            public void onAnimationStart(Animation animation) {

                            }

                            @Override
                            public void onAnimationEnd(Animation animation) {
                                bottomBar.setVisibility(View.GONE);
                                fab.hide(true);
                            }

                            @Override
                            public void onAnimationRepeat(Animation animation) {

                            }
                        });

                        bottomBar.startAnimation(fadeOut);
                        fab.startAnimation(fadeOut);

                    }
                    else if ((bottomBar.getVisibility() == View.GONE)) {

                        fadeIn.setAnimationListener(new Animation.AnimationListener() {
                            @Override
                            public void onAnimationStart(Animation animation) {

                                bottomBar.setVisibility(View.VISIBLE);
                                fab.show(true);
                            }

                            @Override
                            public void onAnimationEnd(Animation animation) {


                            }

                            @Override
                            public void onAnimationRepeat(Animation animation) {

                            }
                        });
                        bottomBar.startAnimation(fadeIn);
                        fab.startAnimation(fadeIn);


                    }
                }
                mLastFirstVisibleItem = firstVisibleItem;



            }
        });

尽管我仍然不理解你想要实现的目标,因为那个动画的逻辑有点奇怪,但仍然应该确定一点点平稳!

修改:更新代码