Android Development Tips--viewpager derived from the 2 classes

Source: Internet
Author: User

1, can not be left and right sliding Viewpager
/* * date:14-7-28 * project:access-control-v2 */package cn.irains.access.v2.common;import android.content.Context; Import Android.support.v4.view.viewpager;import android.util.attributeset;import android.view.motionevent;/** * AUTHOR:MSDX ([email protected]) * time:14-7-28 morning 10:20 */public class Staticviewpager extends Viewpager {public    Sta Ticviewpager (Context context) {        super (context);    }    Public Staticviewpager (context context, AttributeSet Attrs) {        Super (context, attrs);    }    @Override Public    Boolean onintercepttouchevent (motionevent ev) {        return false;    }    @Override Public    Boolean ontouchevent (motionevent ev) {        return false;    }    @Override public    void Setcurrentitem (int item) {        This.setcurrentitem (item, FALSE);}    }

2, the height can be wrapcontent viewpager

/* * date:14-8-18 * project:access-control-v2 */package cn.irains.access.v2.common;import android.content.Context; Import Android.support.v4.view.viewpager;import android.util.attributeset;import android.view.view;/** * Author: MSDX ([email protected]) * time:14-8-18 morning 11:22 */public class Wrapheightviewpager extends Viewpager {public Wra    Pheightviewpager (Context context) {super (context);    } public Wrapheightviewpager (context context, AttributeSet Attrs) {Super (context, attrs);        } @Override protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {int height = 0;            for (int i = 0; i < Getchildcount (); i++) {View child = Getchildat (i);            Child.measure (Widthmeasurespec, Measurespec.makemeasurespec (0, measurespec.unspecified));            int h = child.getmeasuredheight ();        if (H > Height) height = h; } Heightmeasurespec = Measurespec.makemeasurespec (height, measurespec.exacTLY);    Super.onmeasure (Widthmeasurespec, Heightmeasurespec); }/** * Determines the height of this view * * @param measurespec A Measurespec Packed to an int * @p Aram View the base view with already measured height * @return The height of the view, honoring constraints fro        M Measurespec */private int measureheight (int measurespec, view view) {int result = 0;        int specmode = Measurespec.getmode (Measurespec);        int specsize = measurespec.getsize (Measurespec);        if (Specmode = = measurespec.exactly) {result = Specsize;  } else {//Set the height from the base view if available if (view = null) {result            = View.getmeasuredheight ();            } if (Specmode = = measurespec.at_most) {result = Math.min (result, specsize);    }} return result; }}



Android Development Tips--viewpager derived from the 2 classes

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.