Rolling Processing of nested webview in Android viewpager

Source: Internet
Author: User


1. Implement a custom viewpager instance like this:

import android.content.Context; <br>import android.support.v4.view.ViewPager;  <br>import android.util.AttributeSet; <br>import android.util.Log; <br>import android.view.MotionEvent;public class CustomViewPager extends ViewPager {    private MagazineWebView_WithoutFlipWebView mCurrentPageWebView_; //custom webview    public CustomViewPager(Context context, AttributeSet attrs) {        super(context, attrs);    }    @Override    public boolean onInterceptTouchEvent(MotionEvent event) {        if (Constants.LOGGING) {            Log.v(Constants.LOG_OEAMTC_APP, "CustomViewPager - onInterceptTouchEvent");        }        // if view zoomed out (view starts at 33.12... scale level) ... allow        // zoom within webview, otherwise disallow (allow viewpager to change        // view)        if (mCurrentPageWebView_ != null && (mCurrentPageWebView_.getScale() * 100) > 34) {<br>            Log.v(Constants.LOG_OEAMTC_APP, "CustomViewPager - intrcepted: " + String.valueOf((mCurrentPageWebView_.getScale() * > 100)));<br>            this.requestDisallowInterceptTouchEvent(true);        }        else {            if (mCurrentPageWebView_ != null) {                Log.v(Constants.LOG_OEAMTC_APP,                        "CustomViewPager - not intrcepted: " + String.valueOf(mCurrentPageWebView_.getScale() * 100));            }            this.requestDisallowInterceptTouchEvent(false);        }        return super.onInterceptTouchEvent(event);    }    public MagazineWebView_WithoutFlipWebView getCurrentPageWebView() {        return mCurrentPageWebView_;    }    public void setCurrentPageWebView(MagazineWebView_WithoutFlipWebView currentPageWebView) {        mCurrentPageWebView_ = currentPageWebView;    }}

2. In your main (viewpager) activity Add the following lines to the view Pager

mViewPager_ = new AwesomePagerAdapter();<br>        viewpapgerInLayout = (CustomViewPager) findViewById(R.id.awesomepager);<br>        viewpapgerInLayout.setAdapter(mViewPager_);<br>        viewpapgerInLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {<br>                        @Override            public void onPageSelected(int position) {                  viewpapgerInLayout.setCurrentPageWebView(mLstPagesWebviews_.get(position));            }            @Override            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {            }            @Override            public void onPageScrollStateChanged(int state) {            }        });

3. Finally, run it: =)If the zoom level is at initial zoom, changes pages is allowed, all the other time you can navigate your Web View

PS .:*Don't forget* To change your viewpager in your *. xml file with the customviewpager class you just created

Good luck

Share | edit | flag Edited
Jul 26 at 13:17

Asok
37610
Answered
Jan 20

Cv2
631414

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.