TextSwitcher与TextView的功能有点相似,它们都可用于显示文本内容,区别在于TextSwitcher的效果更炫,它可以指定文本切换时的动画效果。 -- 定义一个TextSwitcher,并指定了文本切换时的动画效果 --> <TextSwitcher android:id="@+id/textSwitcher" 接下来Activity只要为TextSwitcher设置ViewFactory,该TextSwitcher即可正常工作。 , "TextSwitcher", "你会了吗?" 当程序要切换TextSwitcher显示文本时,调用TextSwitcher的setText()方法修改文本即可。
image.png 目录 TextSwitcher TextSwitcher 继承自ViewSwitcher, ViewSwitcher继承自ViewAnimator. 使用其实现文字的切换. 使用方式: <TextSwitcher android:id="@+id/textSwitcher" android:layout_width="400dp" android:layout_height="400dp"> </TextSwitcher> 使用实例 activity_main.xml文件: <? android:id="@+id/<em>textSwitcher</em>" android:layout_width="400dp" android:layout_height mtestSwitcher = (TextSwitcher) findViewById(R.id.textSwitcher); //设置Factory
介绍: 1.TextSwitcher是ViewSwicher的一个子类,继承了ViewSwicher的所有方法 2.与ViewSwitcher的另一个子类类似,TextSwitcher也有 3.ImageSwitcher 不同的是:TextSwitcher的ViewFactory方法的 makeVieW() 必须放回一个TextXiew组件. []{ "我爱高数", "我爱概率论", "我爱计算机网络", "我爱操作系统" }; TextSwitcher textSwitcher; int curStr ; Handler handler = new Handler(){ @Override public = (TextSwitcher) findViewById(R.id.textSwitcher); textSwitcher.setFactory(new ViewSwitcher.ViewFactory
项目源码下载:https://github.com/libin7278/TextSwitcher TextSwitcher使用方法 四部曲 1:布局并初始化 <TextSwitcher android /** * 自动垂直滚动的TextView */ public class AutoVerticalScrollTextView extends TextSwitcher implements ViewSwitcher.ViewFactory 1000); return animationSet; } } 如想要了解更多项目详细代码可以访问github: https://github.com/libin7278/TextSwitcher
8.2.3.文本切换器 文本切换器(TextSwitcher)是 Android 中一个集成化较高的控件,可以在多个文本之间切换,还可以设置动画的效果。 参考示例程序:TextSwitcher1(ApiDemo=>Views=>TextSwitcher) 源代码:com/example/android/apis/view/TextSwitcher1.java 布局文件:text_switcher_1.xml TextSwitcher1 程序的运行结果如图所示: ? TextSwitcher 类设置了动画: public class TextSwitcher1 extends Activity implements ViewSwitcher.ViewFactory 这个示例中主要变化的内容,是通过 TextSwitcher 类的 setText()函数来完成的: private void updateCounter() { mSwitcher.setText
android.view.animation.Animation; import android.view.animation.Transformation; import android.widget.TextSwitcher import android.widget.ViewSwitcher; import com.jky.mobilebzt.R; public class AutoTextView extends TextSwitcher mInDown = createAnim(90, 0, true, false); mOutDown = createAnim(0, -90, false, false); //TextSwitcher
ViewAnimator有几个子类:TextSwitcher,ImageSwitcher,ViewSwitcher,ViewFlipper。 通过源码可以知道TextSwitcher,ImageSwitcher其实就是严格限定子view是TextView和ImageView,同时提供更方便的函数来处理text或image。
this.ButPrevious.setEnabled(false); // button不可用 } else { this.ButPrevious.setEnabled(true); // button可用 } } } Textswitcher
前面两期学习了 ViewAnimator及其子类ViewSwitcher的使用,以及ViewSwitcher的子类ImageSwitcher和TextSwitcher的使用,你都掌握了吗?
首先最简单的两个动画,写在了XML里面,当然也可以写到java中, 第一个in_animation.xml,第二个out_animation.xml, 第一步:Android里面已经有了TextSwitcher
ImageSwitcher实质是个视图动画师ViewAnimator,用于处理前后图像的变换动画;与之对应的是,TextSwitcher用于处理前后文本的变换动画;另外ViewFlipper也是从ViewAnimator
附上之前记录的一些动画效果 自定义view:TextSwitcher使用 自定义view:信息飘窗/弹幕——AutoSwitchTextView 自定义view:ProgressBar 前景色、背景色、