一. 简单示例
src
public class AndroidUIActivity extends Activity {
// 索引
private int index;
// 文本数组
private String[] poemArray = { "we", "are", "good", "friends" };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//定义文字切换器
final TextSwitcher ts = (TextSwitcher) findViewById(R.id.textSwitcher1);
//定义视图显示工厂,并设置
ts.setFactory(new ViewFactory() {
public View makeView() {
TextView tv =new TextView(AndroidUIActivity.this);
tv.setTextSize(32);
tv.setTextColor(Color.GREEN);
return tv;
}
});
// 设置图片来源
ts.setText(poemArray[index]);
// 设置点击监听器
ts.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// 点击会切换图片
index++;
if (index >= poemArray.length) {
index = 0;
}
ts.setText(poemArray[index]);
}
});
// 设置切入动画
ts.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.slide_in_left));
// 设置切出动画
ts.setOutAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.slide_out_right));
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextSwitcher
android:id="@+id/textSwitcher1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TextSwitcher>
</LinearLayout>
二. 运行结果
启动
点击we后(只能点击文字)
分享到:
相关推荐
android-TextSwitcher-master.zip对你的学习会有帮助的
Android 中textSwitcher与imageSwitcher的使用
NULL 博文链接:https://lovezhou.iteye.com/blog/849129
Android TextSwitcher Demo 实例
主要介绍了Android TextSwitcher实现文字上下翻牌效果(铜板街),需要的朋友可以参考下
主要为大家详细介绍了Android TextSwitcher文本切换器和ViewFlipper的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
使用TextSwitcher实现多个文字从下到上轮播出现,点击后跳转到相对应界面
主要介绍了Android开发实现自动切换文字TextSwitcher功能,结合实例形式详细分析了Android使用TextSwitcher实现文字自动切换的原理、实现方法及相关操作注意事项,需要的朋友可以参考下
主要介绍了Android 上下滚动TextSwitcher实例详解的相关资料,需要的朋友可以参考下
android官方的textswitcher demo,textview内容的切换(带动画效果)。
该资源主要讲解ViewSwitcher 下的ImageSwitcher和TextSwitcher 的实现实例,希望对你有帮助,免费下载!
TextSwitcher:仿京东、淘宝滚动小广播,实现文字轮播滚动
TextSwitcher:搜索框仿京东、淘宝滚动小广播,实现文字轮播滚动
Android2.2 r1 API 中文文档,注意这里只有TextSwitcher的,请关注over140.cnblogs.com的更新。期待大家一起参与!我的邮箱over140@gmail.com
TextView实现文字的跑马灯效果&TextSwitcher实现文字竖直飞出和飞入,使用的纯代码布局方式。
仿照Google 在卡片上滚动显示最新评论的TextSwitcher