一. 简单示例

src

public class AndroidUIActivity extends Activity {// 索引private int index;// 文本数组private String[] poemArray = { "we", "are", "good", "friends" };/** Called when the activity is first created. */@Overridepublic 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后(只能点击文字)


更多相关文章

  1. Android(安卓)Dialog定义没有标题的注意事项
  2. Android(安卓)Widget 小部件(四---完结) 使用ListView、GridView
  3. Android(安卓)tab 背景及字体颜色设置
  4. Android(安卓)View (transship)
  5. 关于 Activity 中 must implement OnFragmentInteractionListene
  6. Android_开发 Android中CookieManager的底层实现
  7. android 学习记录
  8. android 使用命令模拟点击 滑动
  9. Android(安卓)导航类型

随机推荐

  1. Web应用优化 - 优化切页模式
  2. S3存储桶数据加密设定
  3. 执行 brew install 命令长时间卡在 Updat
  4. Web 应用优化 - 按需加载资源
  5. GitHub 个人首页如何定制
  6. ITSS运维资质认证评审需要哪些材料?
  7. jQuery方法使用
  8. 0413作业-jQuery常用方法
  9. i5 9400和9400f区别 i5 9400和9400哪个好
  10. (4-15)红黑树