Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何同时同步滚动视图_Android_Scrollview - Fatal编程技术网

Android 如何同时同步滚动视图

Android 如何同时同步滚动视图,android,scrollview,Android,Scrollview,我曾经同步2个滚动视图。我希望我们实现一个接口 CrollChanged上的受保护无效(int x,int y,int oldx,int oldy) 现在有谁能告诉我如何使用这个接口或任何其他方法来同时同步四个视图,因为onScrollChanged()在内置方法中,并且只使用两个滚动视图的坐标。但我必须滚动4个视图。如果有什么办法,请告诉我。提前谢谢。我想你可以这样做 if(scrollView == scrollView1) { scrollView2.scrollT

我曾经同步2个滚动视图。我希望我们实现一个接口

CrollChanged上的受保护无效(int x,int y,int oldx,int oldy)


现在有谁能告诉我如何使用这个接口或任何其他方法来同时同步四个视图,因为onScrollChanged()在内置方法中,并且只使用两个滚动视图的坐标。但我必须滚动4个视图。如果有什么办法,请告诉我。提前谢谢。

我想你可以这样做

    if(scrollView == scrollView1) {
        scrollView2.scrollTo(x, y);
        scrollView3.scrollTo(x, y);
        scrollView4.scrollTo(x, y);
    } else if(scrollView == scrollView2) {
        scrollView1.scrollTo(x, y);
        scrollView3.scrollTo(x, y);
        scrollView4.scrollTo(x, y);
    } else if(scrollView == scrollView3) {
        scrollView1.scrollTo(x, y);
        scrollView2.scrollTo(x, y);
        scrollView4.scrollTo(x, y);
    } else if(scrollView == scrollView4) {
        scrollView1.scrollTo(x, y);
        scrollView2.scrollTo(x, y);
        scrollView3.scrollTo(x, y);
    }

谢谢你的回复。我试过了,但它在scrollview3上出现了nullpointer异常。是否对Onscrollchanged界面进行了一些修改。因为它负责滚动。这就是scollView3!=在onCreate中为空?也许您可以先调用findViewById 4次,然后设置setScrollViewListener:这样可以避免在创建/初始化scollView3/4之前调用onScrollChanged。非常感谢。那很好。让我继续前进