個人是在viewpager中某個fragment中有gallery... 致使沒法滑動,網上找到解決方法,主要是紅色的代碼。android
自定義Gallery. ide
import android.content.Context; import android.support.v4.view.ViewPager; import android.util.AttributeSet; import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; import android.widget.Gallery; public class CustomGallery extends Gallery implements OnGestureListener { private ViewPager mPager; public ViewPager getmPager() { return mPager; } public void setmPager(ViewPager mPager) { this.mPager = mPager; } /** * @param context * @param attrs */ public CustomGallery(Context context) { super(context); // TODO Auto-generated constructor stub } /** * @param context * @param attrs * */ public CustomGallery(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override public boolean dispatchTouchEvent(MotionEvent ev) { // TODO Auto-generated method stub mPager.requestDisallowInterceptTouchEvent(true); return super.dispatchTouchEvent(ev); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { // TODO Auto-generated method stub mPager.requestDisallowInterceptTouchEvent(true); return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub mPager.requestDisallowInterceptTouchEvent(true); return super.onTouchEvent(event); } }其餘自定義控件也同樣,可把這三個方法添加都自定義類當中便可。