Scrollbar touch area in Android 6

廉价感情. 提交于 2019-12-05 04:55:20

I encountered the same issue and ended up using a workaround.

The trick is to disable the fast scroll when the user is not scrolling (or 1 sec after he stopped scrolling), and reactivate it when he starts scrolling again. In order to do so, youn need to implement OnScrollListener like this and set the listener to the listview:

private int mCurrentState = 0;

@Override
public void onScrollStateChanged(AbsListView absListView, int state) {

    if (state == SCROLL_STATE_IDLE && mCurrentState != state && mListview.isFastScrollEnabled()){

        mListview.postDelayed(new Runnable() {
            @Override
            public void run() {
                mListview.setFastScrollEnabled(false);
            }
        },1000);

    }

    mCurrentState = state;
}

@Override
public void onScroll(AbsListView absListView, int i, int i1, int i2) {

    if (mCurrentState == SCROLL_STATE_TOUCH_SCROLL) {


        if (!mListview.isFastScrollEnabled())
            mListview.setFastScrollEnabled(true);
    }
}

Hope this might help you

Found a simple solution which honestly I don't understand completely ;) I created a view overlay for the blue section which should be touch insensitive for the fastscrollbar (parent view is a RelativeLayout).

<View
    android:id="@+id/scroll_overlay
    android:layout_width="25dp"
    android:layout_marginRight="25dp"
    android:alignParentTop="true"
    android:alignParentRight="true"
    android:layout_above="@id/my_list_view_bottom_bar"
    android:clickable="true"/>

Then in my list view fragment, I set up an OnTouchListener for the overlay view to catch the touch events. The idea was to catch the MotionEvent.ACTION_DOWN to avoid jumping to the fast scrollbar position. But following code does that already.

View scrollOverlay = (View)view.findViewById(R.id.scroll_overlay);
scrollOverlay.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
      return myListView.onTouchEvent(event);
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!