同步两个ExpandableListView中的滚动

时间:2016-08-15 10:45:59

标签: java android expandablelistview

我有两个ExpandableListView,它们彼此靠近。是否可以在两者中同步滚动?假设用户是否开始滚动,在第一个ExpandableListView开始滚动,也会在第二个ExpandableListView中滚动?

例如,前三列(第二行)是第一个ExpandableListView,最后一个是第二个ExpandableListView。 (见图)

enter image description here

1 个答案:

答案 0 :(得分:1)

这是一个有趣的问题。我发明了这个概念验证github gist

此解决方案依赖于 View.OnTouchListener ,我们通过 dispatchTouchEvent 方法将 MotionEvent 从第一个可扩展视图传递到另一个视图,反之亦然。

这是示例用法:

    ExpandableListViewSynchronisationTouchListener expandableListViewSynchronisationTouchListener = new ExpandableListViewSynchronisationTouchListener(this, firstExpandable, secondExpandable);
    firstExpandable.setOnTouchListener(expandableListViewSynchronisationTouchListener);
    secondExpandable.setOnTouchListener(expandableListViewSynchronisationTouchListener);
    firstExpandable.setOnChildClickListener(expandableListViewSynchronisationTouchListener);
    secondExpandable.setOnChildClickListener(expandableListViewSynchronisationTouchListener);