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