当前位置:网站首页>The solution to the left-right sliding conflict caused by nesting Baidu MapView in the fragment of viewpager

The solution to the left-right sliding conflict caused by nesting Baidu MapView in the fragment of viewpager

2022-07-06 17:29:00 geekqian

Reference material : http://jp1017.top/2016/07/28/ViewPager-%E5%B5%8C%E5%A5%97%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%E4%BA%8B%E4%BB%B6%E5%86%B2%E7%AA%81%E7%9A%84%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95/

That's the problem , I am here ViewPager One of them Fragment Baidu is nested in MapView after , There is a left-right sliding conflict , It's disabled ViewPager The slide of …

I found a wave of information on the Internet , The easiest and most efficient way to find one is to customize it ViewPager , So the code is as follows .

public class MyViewPager extends ViewPager {
    
    public MyViewPager(@NonNull Context context) {
    
        super(context);
    }

    public MyViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
    
        super(context, attrs);
    }

    @Override
    protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    
        return v.getClass().getName().equals("com.baidu.mapapi.map.MapView")
                || v.getClass().getName().equals("com.amap.api.maps.MapView")
                || super.canScroll(v, checkV, dx, x, y);
    }
}

Then right-click this customized ViewPager choice “Copy Reference” Copy relative paths , Replace the original “androidx.viewpager.widget.ViewPager”.

The running result perfectly solves this problem .

原网站

版权声明
本文为[geekqian]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131311066953.html