android的ViewFlipper
activity_main.xml
目前成都创新互联已为1000+的企业提供了网站建设、域名、虚拟主机、绵阳服务器托管、企业网站设计、宁远网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
res/anim/in_leftright.xml
res/anim/in_rightleft.xml
res/anim/out_leftright.xml
res/anim/out_rightleft.xml
MainActivity
package com.example.viewflipper; import android.R.integer; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.widget.ViewFlipper; public class MainActivity extends Activity { private ViewFlipper viewFilpper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); viewFilpper=(ViewFlipper) findViewById(R.id.viewFlipper_1); } //重写触屏事件监听方法 float startx=0.0F; float endx=0.0F; @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub int action=event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: startx=event.getX(); break; case MotionEvent.ACTION_UP: //向右滑动 if(event.getX()-startx>10){ viewFilpper.setInAnimation(this, R.anim.in_leftright); viewFilpper.setOutAnimation(this, R.anim.out_leftright); viewFilpper.showNext(); }else if(startx-event.getX()>10){ viewFilpper.setInAnimation(this, R.anim.in_rightleft); viewFilpper.setOutAnimation(this, R.anim.out_rightleft); viewFilpper.showPrevious(); } break; default: break; } return super.onTouchEvent(event); } }
本文标题:android的ViewFlipper
文章地址:http://myzitong.com/article/gsdehc.html