Android工具栏小动作导致弹跳

时间:2015-07-20 01:21:40

标签: android scroll toolbar android-recyclerview

当向上滚动视图时我的工具栏应该被隐藏,向下滚动时它将返回。小动作会产生奇怪的效果;如果我做一个小动作,工具栏就会反弹,如果我想移动视图并且不会导致弹跳,我会有一个小空间。

XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/Friends"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways" />

        <View
            android:layout_width="match_parent"
            android:layout_height="0.00001px"
            android:background="@android:color/transparent"
            android:visibility="invisible" />

    </android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

显示输入的示例(白色圆圈):

enter image description here

1 个答案:

答案 0 :(得分:0)

试试这个

mListView.setOverScrollMode(View.OVER_SCROLL_NEVER);
if(Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD || Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD_MR1){
    mListView.setOnScrollListener(new OnScrollListener(){
        private boolean flinging = false;
        private boolean reachedEnd = false;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            flinging = (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING);
            reachedEnd = false;
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if(reachedEnd && flinging && (firstVisibleItem + visibleItemCount < totalItemCount)){
                mListView.setSelection(mAdapter.getCount() - 1);
            }else if(firstVisibleItem + visibleItemCount == totalItemCount){
                reachedEnd = true;
            }else{
                reachedEnd = false;
            }

        }

    });