ViewPager, a component that slides up and down, and VerticalPager slides up and down on android

Source: Internet
Author: User

ViewPager, a component that slides up and down, and VerticalPager slides up and down on android

package com.zhulin.android.atools;import android.content.Context;import android.util.AttributeSet;import android.util.Log;import android.view.MotionEvent;import android.view.VelocityTracker;import android.view.View;import android.view.ViewGroup;import android.view.animation.Interpolator;import android.widget.Scroller;import android.widget.Toast;public class VerticalPager extends ViewGroup{private Scroller mScroller;private Context mContext;public VerticalPager(Context context, AttributeSet attrs) {super(context, attrs);this.mContext=context;mScroller=new Scroller(context);//mScroller=new Scroller(mContext, new Interpolator() {////@Override//public float getInterpolation(float input) {//return 300;//}//});}@Overrideprotected void onLayout(boolean changed, int l, int t, int r, int b) {int totalHeight=0;int count=getChildCount();for(int i=0;i
 
  (getHeight()*(getChildCount()-1))){View lastView=getChildAt(getChildCount()-1);mScroller.startScroll(0,lastView.getTop()+300, 0, -300);}else{int position=getScrollY()/getHeight();int mod=getScrollY()%getHeight();if(mod>getHeight()/3){View positionView=getChildAt(position+1);mScroller.startScroll(0, positionView.getTop()-300, 0, +300);}else{View positionView=getChildAt(position);mScroller.startScroll(0, positionView.getTop()+300, 0, -300);}}invalidate();break;//case MotionEvent.ACTION_MASK://if(getScrollY()<0){//mScroller.startScroll(0, 0, 0, 0);//}else if(getScrollY()>(getHeight()*(getChildCount()-1)){//}//invalidate();//break;}return true;}@Overridepublic void computeScroll() {super.computeScroll();if(mScroller.computeScrollOffset()){scrollTo(0, mScroller.getCurrY());}else{}}}
 

Xml Layout

 
     
          
           
                    
                      
       
  
 


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.