Android之TextSwitcher
2011-11-07 13:56
218 查看
一. 简单示例
src
main.xml
二. 运行结果
启动
点击we后(只能点击文字)
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 中文 API (17) —— TextSwitcher
- Android TextSwitcher - 文本切换器
- Android 头部设置上下滚动的消息列表 TextView (TextSwitcher运用)
- android的ImageSwitcher和TextSwitcher
- Android之TextSwitcher----ImageSwitcher
- android 之 TextSwitcher 学习
- Android UI之ImageSwitcher && TextSwitcher 实现图文翻页
- Android 中文 API (17) —— TextSwitcher
- Android 中文 API (17) —— TextSwitcher
- Android仿淘宝商品自动滚动 ImageSwitcher和TextSwitcher的用法
- Android学习之路---ImageSwitcher和TextSwitcher切换图片及文本
- Android TextSwitcher
- android viewanimator viewfilter viewswitcher textswitcher imageswitcher
- Android ViewSwitcher、TextSwitcher、ImageSwitcher
- Android之TextSwitcher详解
- 上接系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, ImageSwitcher, GridView, ListView
- 【Android开发】TextSwitcher 使用详解
- 系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, ImageSwitcher, GridView, ListView
- Android_TextSwitcher和ImageSwitcher
- Android_TextSwitcher和ImageSwitcher