列表视图滚动时隐藏屏幕底部的linearlayout

时间:2016-06-07 07:00:50

标签: android animation onscroll onscrolllistener

我有一个自定义列表视图和一个带有textview的线性布局,位于屏幕底部。我已经实现了一个OnScrollListener来在滚动时隐藏actionbar和linearlayout,并在滚动完成后返回。动作栏平滑地隐藏,没有任何闪烁和口吃,但线性布局不是。我正在使用动画隐藏布局,但我无法完全实现。我需要布局应该隐藏像twitter应用程序,其中底部布局在滚动时平滑地隐藏。请帮忙。

mViews.lists.setOnScrollListener(new AbsListView.OnScrollListener() {
        int mLastFirstVisibleItem = 0;
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            android.support.v7.app.ActionBar actionBar = getSupportActionBar();
            if (view.getId() == mViews.lists.getId()) {
                final int currentFirstVisibleItem =  mViews.lists.getFirstVisiblePosition();

                if (currentFirstVisibleItem > mLastFirstVisibleItem) {
                    // getSherlockActivity().getSupportActionBar().hide();
                    if (actionBar != null) {
                        actionBar.hide();
                       mViews.linear.startAnimation(animHide);
                       mViews.linear.setVisibility(View.GONE);



                    }
                } else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
                    // getSherlockActivity().getSupportActionBar().show();
                    actionBar.show();
                 mViews.linear.startAnimation(animShow);
                    mViews.linear.setVisibility(View.VISIBLE);



                }

                mLastFirstVisibleItem = currentFirstVisibleItem;
            }
        }
    });

隐藏并显示xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
    android:fromYScale="1.0"
    android:interpolator="@android:anim/linear_interpolator"
    android:toYScale="0.0" />
</set>



<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >

<scale
    android:fromYScale="0.0"
    android:interpolator="@android:anim/linear_interpolator"
    android:toYScale="1.0" />
</set>

1 个答案:

答案 0 :(得分:0)

试试这个:

lv.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

            if(scrollState == SCROLL_STATE_TOUCH_SCROLL){

             //Paste here the code for hiding the layout

            }else{

             //Paste here the code for showing the layout

            }
        }

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

        }
  });