Android组件ViewFlipper的使用

时间:2016-01-14 04:55:38
【文件属性】:
文件名称:Android组件ViewFlipper的使用
文件大小:455KB
文件格式:RAR
更新时间:2016-01-14 04:55:38
Android ViewFlipper 使用ViewFlipper的手势功能完成的图像之间的切换、 package com.action; import android.app.Activity; import android.os.Bundle; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import android.view.GestureDetector.OnGestureListener; import android.view.View.OnTouchListener; import android.view.animation.AlphaAnimation; import android.view.animation.AnimationUtils; import android.widget.ImageView; import android.widget.ViewFlipper; public class MainFlingDemoActivity extends Activity implements OnGestureListener { /** Called when the activity is first created. */ private ViewFlipper vf; private GestureDetector detector; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView iv1=new ImageView(this); ImageView iv2=new ImageView(this); ImageView iv3=new ImageView(this); iv1.setImageResource(R.drawable.a1); iv2.setImageResource(R.drawable.a2); iv3.setImageResource(R.drawable.a3); detector = new GestureDetector(this); vf=(ViewFlipper) findViewById(R.id.viewFlipper1); AlphaAnimation an=new AlphaAnimation(0.1f,1.0f); an.setDuration(1000); vf.setAnimation(an); vf.addView(iv1, 0); vf.setAnimation(an); vf.addView(iv2, 1); vf.setAnimation(an); vf.addView(iv3, 2); vf.setAnimation(an); if(detector.isLongpressEnabled()){ vf.setFlipInterval(5000); vf.startFlipping(); } } @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub return this.detector.onTouchEvent(event); } @Override public boolean onDown(MotionEvent e) { // TODO Auto-generated method stub return false; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // TODO Auto-generated method stub System.out.println("==============="); //vf.stopFlipping(); if (e1.getX() - e2.getX() > 120) { this.vf.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); this.vf.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); this.vf.showNext(); return true; } else if (e1.getX() - e2.getX() < -120) { this.vf.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); this.vf.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); this.vf.showPrevious(); return true; } if (e1.getY() - e2.getY() > 120) { this.vf.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); this.vf.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); this.vf.showNext(); return true; } else if (e1.getY() - e2.getY() < -120) { this.vf.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); this.vf.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); this.vf.showPrevious(); return true; } return false; } @Override public void onLongPress(MotionEvent e) { // TODO Auto-generated method stub //vf.startFlipping(); } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // TODO Auto-generated method stub return false; } @Override public void onShowPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onSingleTapUp(MotionEvent e) { // TODO Auto-generated method stub return false; } }
【文件预览】:
prjFlingDemo
----AndroidManifest.xml(965B)
----res()
--------layout()
--------drawable-ldpi()
--------drawable-mdpi()
--------drawable-hdpi()
--------values()
----proguard.cfg(1KB)
----src()
--------com()
----bin()
--------classes()
--------res()
--------prjFlingDemo.apk(154KB)
--------classes.dex(5KB)
--------resources.ap_(150KB)
----.classpath(364B)
----assets()
----project.properties(360B)
----.project(848B)
----gen()
--------com()

网友评论

  • 不是gradle项目啊 提示
  • 代码很不错,调整一下就可以用了
  • 谢谢,刚好用到项目上!
  • 代码很不错,调整一下就可以用了
  • 下载下来可以使用
  • 经实践,可用,不错,谢谢楼主!
  • 很不错的东西,有用有用
  • 认真学习下了
  • 不好用,下一张没问题,上一张有bug
  • 学习 受用 感谢楼主
  • 下载下来可以使用