Thursday, July 19, 2012

not horizontal scroll child view as gallery or webview inside view pager

you can override this method in your child view

public class CoverFlow extends Gallery {    public CoverFlow(Context context) {        super(context);

    public CoverFlow(Context context, AttributeSet attrs) {        super(context, attrs);

    public boolean canScrollHor(int direction) {
        final int offset = computeHorizontalScrollOffset();
        final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent();
        if (range == 0) return false;
        if (direction < 0) {
            return offset > 0;
        } else {
            return offset < range - 1;
you can detect onTouch event in view Pager.if touch comes from your child view then call the child view event function and perform action otherwise simply you returns viewpager canScroll event.
public class MyViewPager extends ViewPager {
    public MyViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);

    protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
        if (v instanceof CoverFlow) {
            //return your child view event
         return true;
        } else {
          //return your view Pager event
return super.canScroll(v, checkV, dx, x, y); } } }

No comments:

Post a Comment