本文为大家分享了Android TextSwitcher文本切换器的使用,供大家参考,具体内容如下
1.TextSwitcher
使用:
应用分为三步:
1.得到 TextSwitcher 实例对象
TextSwitcher switcher = (TextSwitcher) findViewById(R.id.textSwitcher);
2.为switcher指定ViewSwitcher.ViewFactory工厂,该工厂会产生出转换时需要的View
switcher.setFactory(this);
3.为switcher设定显示的内容,该方法执行,就会切换到下个View
switcher.setText(String.valueOf(new Random().nextInt()));
2.ViewFlipper
实现:
①创建主布局文件,包含ViewFlipper控件(从源码来看,ViewFlipper控件是集成FrameLayout,也是相当于一个帧布局,只是包含了一些特殊的属性)
②创建ViewFlipper的子View,就是两个LinearLayout(里面包含两个TextView)
③创建ViewFlipper中子view的进入和退出动画anim_in和anim_out两个动画文件
④在Activity中将两个子View添加到ViewFlipper中去,调动的是ViewFlipper的addView方法
具体代码:
①创建主布局文件
activity_main.xml
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.andro