ImageSwitcher,TextSwitcher实现图片,文字切换
2016-06-25 18:14
585 查看
ImageSwitcher想实现自动播放可以添加线程中
TextSwitcher使用方法:
《Android版本更新、热更新》系列课程视频
版本更新6.0,7.0统统搞定!!
热修复不在麻烦,再也不用担心上线后出bug!!
http://edu.csdn.net/course/detail/6523
http://edu.csdn.net/course/play/6523/131198
《Kotlin语法基础到实战开发》系列课程视频
http://edu.csdn.net/course/detail/6409?locationNum=7&fps=1&ref=srch&loc=1
http://edu.csdn.net/course/play/6409/123752
public class MyImageSwitch extends Activity implements ViewFactory,OnTouchListener{ private ImageSwitcher is; private int [] images={R.drawable.btn_casepx_normal, R.drawable.btn_casepx_press,R.drawable.btn_casequery_press,R.drawable.btn_casepx_press,R.drawable.btn_casequery_press}; private int index; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.imageswitchs); is=(ImageSwitcher) findViewById(R.id.Image); is.setOnTouchListener(this); is.setFactory(this); } @Override public View makeView() { ImageView iv=new ImageView(this); iv.setImageResource(images[0]); return iv; } float start=0.0f; float end=0.0f; //实现触屏 @Override public boolean onTouch(View view, MotionEvent event) { int action = event.getAction();//获取当前的动作 if(action==MotionEvent.ACTION_DOWN){ //当点下去的时候 start = event.getX(); return true; } if(action==MotionEvent.ACTION_UP){//获取当你点击完后的x轴 end = event.getX(); return true; } if(start-end>100){ //像左 index=index+1<images.length ? ++index : 0; is.setInAnimation(this,android.R.anim.fade_in);//设置进的动画 is.setOutAnimation(this,android.R.anim.fade_out);//设置出的动画 }else if(end-start>20){ index=index-1>=0 ? --index:images.length-1; is.setInAnimation(this,android.R.anim.fade_in);//设置进的动画 is.setOutAnimation(this,android.R.anim.fade_out);//设置出的动画 } is.setImageResource(images[index]); return true; } }
TextSwitcher使用方法:
public class MytextSwitch extends Activity implements ViewFactory ,OnTouchListener{ private TextSwitcher tsw; private String [] texts={"付出一定有回报","人生巅峰","我有钱,我任性"}; private int index=0; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.mytext); tsw=(TextSwitcher) findViewById(R.id.textswitch); tsw.setOnTouchListener(this); tsw.setFactory(this); } @Override public View makeView() { TextView tv=new TextView(this); tv.setText(texts[index]); return tv; } float start=0.0f; float end=0.0f; @Override public boolean onTouch(View arg0, MotionEvent event) { int action = event.getAction();//获取当前的动作 if(action==MotionEvent.ACTION_DOWN){ //当点下去的时候 start = event.getX(); return true; } if(action==MotionEvent.ACTION_UP){//获取当你点击完后的x轴 end = event.getX(); return true; } if(start-end>50){ //像左 index=index+1<texts.length ? ++index : 0; tsw.setInAnimation(this,android.R.anim.fade_in);//设置进的动画 tsw.setOutAnimation(this,android.R.anim.fade_out);//设置出的动画 }else if(end-start>50){ index=index-1>=0 ? --index:texts.length-1; tsw.setInAnimation(this,android.R.anim.fade_in);//设置进的动画 tsw.setOutAnimation(this,android.R.anim.fade_out);//设置出的动画 } tsw.setText(texts[index]); return true; } }
《Android版本更新、热更新》系列课程视频
版本更新6.0,7.0统统搞定!!
热修复不在麻烦,再也不用担心上线后出bug!!
http://edu.csdn.net/course/detail/6523
http://edu.csdn.net/course/play/6523/131198
《Kotlin语法基础到实战开发》系列课程视频
http://edu.csdn.net/course/detail/6409?locationNum=7&fps=1&ref=srch&loc=1
http://edu.csdn.net/course/play/6409/123752
相关文章推荐
- ConnectionResetError: [Errno 104] Connection reset by peer
- 【iOS开发】强制修改 iOS 状态栏颜色
- 数据库连接池性能比对
- Unity3D游戏引擎基础教程
- poj 1068--Parencodings
- IOS开发之功能模块--输入框随着键盘的位置移动而移动
- Ubuntu12.04安装java8
- jQuery 3.0 的变化
- tomcat启动闪退
- C++12、模板
- gdb 查看当前位置的指令
- 记录一次logstash 死锁问题
- emWin实现BMP位图皮肤之Radio篇
- android中handler和looper的工作原理
- StudyJams-第05课_嵌套布局和字符串
- 易宝支付流程
- Win10默认开启数字小键盘的方法
- druid 源码分析与学习(含详细监控设计思路的彩蛋)
- hibernate+strutes结合的图书馆管理系统
- 做个图片的防盗链