Synchronize two ListView positions

后端 未结 2 1695
自闭症患者
自闭症患者 2021-02-10 15:29

I have two ListViews. Is there any way to synchronize the position of ListViews when I scroll any one of the Lists

2条回答
  •  忘了有多久
    2021-02-10 16:05

    We did this and it worked well for us.

    listOne.setOnTouchListener(new OnTouchListener() {
        @Override
           public boolean onTouch(View arg0, MotionEvent arg1) {
           listTwo.dispatchTouchEvent(arg1);
           return false;
        }
    });
    listOne.setOnScrollListener(new OnScrollListener() {
       @Override
       public void onScrollStateChanged(AbsListView arg0, int arg1) {
       }
       @Override
       public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) {
              if (l1.getChildAt(0) != null) {
                  Rect r = new Rect();
                  l1.getChildVisibleRect(l1.getChildAt(0), r, null);
                  l2.setSelectionFromTop(l1.getFirstVisiblePosition(), r.top);
              }
        }
    });
    

提交回复
热议问题