堅向的ViewPager,上下滑動的組件,android上下滑動 VerticalPager,viewpager上下滑動

來源:互聯網
上載者:User

堅向的ViewPager,上下滑動的組件,android上下滑動 VerticalPager,viewpager上下滑動

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<count;i++){View childView=getChildAt(i);//int measureHeight=childView.getMeasuredHeight();//int measureWidth=childView.getMeasuredWidth();childView.layout(l, totalHeight, r, totalHeight+b);totalHeight+=b;}}private VelocityTracker mVelocityTracker;@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int width=MeasureSpec.getSize(widthMeasureSpec);int height=MeasureSpec.getSize(heightMeasureSpec);int count=getChildCount();for(int i=0;i<count;i++){getChildAt(i).measure(width, height);}setMeasuredDimension(width, height);}private int mLastMotionY;@Overridepublic boolean onTouchEvent(MotionEvent event) {if(mVelocityTracker==null){mVelocityTracker=VelocityTracker.obtain();}mVelocityTracker.addMovement(event);int action=event.getAction();float y=event.getY();switch(action){case MotionEvent.ACTION_DOWN:if(!mScroller.isFinished()){mScroller.abortAnimation();}mLastMotionY=(int) y;Log.d("montion", ""+getScrollY());break;case MotionEvent.ACTION_MOVE:int deltaY=(int) (mLastMotionY-y);scrollBy(0,deltaY);//mScroller.startScroll(0, getScrollY(), 0, deltaY);invalidate();mLastMotionY=(int) y;break;case MotionEvent.ACTION_UP:if(mVelocityTracker!=null){mVelocityTracker.recycle();mVelocityTracker=null;}if(getScrollY()<0){mScroller.startScroll(0, -400, 0, 400);}else if(getScrollY()>(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布局

<?xml version="1.0" encoding="UTF-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <com.zhulin.android.atools.VerticalPager        android:id="@+id/vertyPager1"        android:layout_width="fill_parent"        android:layout_height="fill_parent" >        <TextView            android:background="@drawable/a1"            android:id="@+id/textView1"            android:layout_width="match_parent"            android:layout_height="100dp"            android:text="TextView1111" />        <TextView             android:background="@drawable/a2"            android:id="@+id/textView2"            android:layout_width="fill_parent"            android:layout_height="100dp"            android:text="TextView2222" />                 <TextView             android:background="@drawable/a3"            android:id="@+id/textView3"            android:layout_width="fill_parent"            android:layout_height="100dp"            android:text="TextView2222" />                   <TextView             android:background="@drawable/a4"            android:id="@+id/textView4"            android:layout_width="fill_parent"            android:layout_height="100dp"            android:text="TextView2222" />    </com.zhulin.android.atools.VertyPager></LinearLayout>



android viewpager怎實現螢幕上下切屏效果上下部分源碼

github.com/...wPager

看一下吧,上下滑動的viewpager
 
android怎讓ListView與ViewPager動態圖片一起上下滑動,有木有給下思路

把ViewPager做成ListView的Header就可以了ListView.addHeaderView()
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.