本文主要是介绍页面水平滑动之ViewFlipper,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
以下内容大部分转自或参考于网络。
常用实现滑动方式有PagerSlidingTabStrip+ViewPager,这里使用ViewFlipper
public class MainActivity : Activity, GestureDetector.IOnGestureListener{ViewFlipper vf;GestureDetector detector;protected override void OnCreate(Bundle bundle){base.OnCreate(bundle);// Set our view from the "main" layout resourceSetContentView(Resource.Layout.Main);detector = new GestureDetector(this);vf = (ViewFlipper)FindViewById(Resource.Id.viewFlipper1);ImageView iv = new ImageView(this);iv.SetBackgroundResource(Resource.Drawable.accept);vf.AddView(iv);ImageView iv2 = new ImageView(this);iv2.SetBackgroundResource(Resource.Drawable.add);vf.AddView(iv2);}public override Boolean OnTouchEvent(MotionEvent e) {// 将触屏事件交给手势识别类处理 return this.detector.OnTouchEvent(e);}public Boolean OnDown(MotionEvent e){return false;}public void OnShowPress(MotionEvent e){}public Boolean OnSingleTapUp(MotionEvent e){return false;}public Boolean OnScroll(MotionEvent e1, MotionEvent e2, float distanceX,float distanceY){return false;}public Boolean OnFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY){if (e1.GetX() - e2.GetX() > 100){this.vf.ShowNext();return true;}if (e1.GetX() - e2.GetX() < -100){this.vf.ShowPrevious();return true;}return false;}public void OnLongPress(MotionEvent e){}}
这篇关于页面水平滑动之ViewFlipper的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!