我有两个 ExpandableListView
,它们彼此靠近。是否可以在两者中同步滚动?假设用户开始滚动,在第一个 ExpandableListView
中开始滚动,也会在第二个 ExpandableListView
中开始滚动?
例如,前三列(第二行)是第一个 ExpandableListView,最后一列是第二个 ExpandableListView。 (见图)
最佳答案
这是一个有趣的问题。我发明了这个概念证明github gist
此解决方案依赖于 View.OnTouchListener,其中我们通过 dispatchTouchEvent 方法将 MotionEvent 从第一个可扩展 View 传递到另一个可扩展 View ,反之亦然。 p>
这是示例用法:
ExpandableListViewSynchronisationTouchListener expandableListViewSynchronisationTouchListener = new ExpandableListViewSynchronisationTouchListener(this, firstExpandable, secondExpandable);
firstExpandable.setOnTouchListener(expandableListViewSynchronisationTouchListener);
secondExpandable.setOnTouchListener(expandableListViewSynchronisationTouchListener);
firstExpandable.setOnChildClickListener(expandableListViewSynchronisationTouchListener);
secondExpandable.setOnChildClickListener(expandableListViewSynchronisationTouchListener);
关于java - 两个ExpandableListView中滚动的同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38953625/