解决ViewPager和HorizontalScrollxxx控件冲突

 最近项目中有用ViewPager里面嵌套HorizontalListView ,结果HorizontalListView不能正常滑动,万能的百度找到了[http://blog.csdn.net/wurensen/article/details/12918621](http://blog.csdn.net/wurensen/article/details/12918621) 这篇文章,真的很不错,解决了我的问题。代码如下:
   public class HorizontalWidgetCanScrollViewPager extends ViewPager {
    public HorizontalWidgetCanScrollViewPager(Context context) {
        this(context, null);
    }

    public HorizontalWidgetCanScrollViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    //这里可以添加其他有冲突的控件
        if (v instanceof HorizontalListView || v instanceof HorizontalScrollView) {
            return true;
        }
        return super.canScroll(v, checkV, dx, x, y);
    }
}

猜你喜欢

转载自blog.csdn.net/nihaomabmt/article/details/72962143
今日推荐