问题:ViewPager里面包含一个HorizontalScrollVIew,ViewPager左右滑动时能够切换Activity,但是HorizontalScrollVIew无法滚动。因此特别写了个详细的方法供大家参考参考,具体如下:
1.自定义一个继承ViewPager的类,如CustomViewPager(例如,在com.eoeandroid.widget 包中创建该类):
- package com.eoeandroid.widget;
-
- import android.content.Context;
- import android.support.v4.view.ViewPager;
- import android.util.AttributeSet;
- import android.view.View;
- import android.widget.HorizontalScrollView;
-
- public class CustomViewPager extends ViewPager {
- public CustomViewPager(Context context) {
- super(context);
- }
-
- public CustomViewPager(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- @Override
- protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
- if (v instanceof HorizontalScrollView) {
- return true;
- }
- return super.canScroll(v, checkV, dx, x, y);
- }
- }
- <com.eoeandroid.widget.CustomViewPager
- android:id="@+id/vPager"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_weight="1.0"
- android:flipInterval="30"
- android:persistentDrawingCache="animation" />