<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent"><TextView android:layout_width="fill_parent"android:layout_height="wrap_content" android:text="TextSwitcher" /><Button android:text="ok" android:id="@+id/Button01"android:layout_width="wrap_content"android:layout_height="wrap_content"></Button><TextSwitcher android:id="@+id/TextSwitcher01"android:layout_width="wrap_content"android:layout_height="wrap_content"></TextSwitcher><TextView android:text="@+id/TextView01"android:id="@+id/TextView01" android:layout_width="wrap_content"android:layout_height="wrap_content"></TextView></LinearLayout>


package com.Aina.Android;import java.util.Random;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.widget.Button;import android.widget.TextSwitcher;import android.widget.TextView;import android.widget.ViewSwitcher;public class Test_TextSwitcher extends Activity implements ViewSwitcher.ViewFactory{    /** Called when the activity is first created. */TextSwitcher ts;TextView tv2;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        Button btn = (Button) this.findViewById(R.id.Button01);        ts = (TextSwitcher) this.findViewById(R.id.TextSwitcher01);        tv2 = (TextView) this.findViewById(R.id.TextView01);        tv2.setTextSize(36);        ts.setFactory(this);// 指定转换器的 ViewSwitcher.ViewFactory        // 设置淡入和淡出的动画效果        Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);        Animation out = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);        ts.setInAnimation(in);        ts.setOutAnimation(out);        btn.setOnClickListener(new Button.OnClickListener(){public void onClick(View v) {String str = String.valueOf(new Random().nextInt());ts.setText(str);tv2.setText(str);}                });    }      // 重写 ViewSwitcher.ViewFactory 的 makeView(),返回一个 Viewpublic View makeView() {TextView tv = new TextView(this);tv.setTextSize(36);return tv;}}

更多相关文章

  1. 重写对话框
  2. Android 之 ImageSwitch图片转换器
  3. 重写EditText回车键跳到下一个EditText
  4. ASP.NET MVC重写的实例教程
  5. 如何区分重载和重写?
  6. 单例模式的十种写法,你会几个?(重写版)
  7. 重写ajax方法实现异步请求session过期时跳转登录页面
  8. PHP的文本到HTML转换器
  9. PHP的$ _GET和URL重写

随机推荐

  1. android Studio Error: 前言中不允许有内
  2. onConfigurationChanged会重新 OnCreate
  3. div+css命名规范 嫁接android xml命名
  4. 我的Android进阶之旅------>Android之选
  5. android-电话拨号器&点击事件四种写法
  6. android 问题汇总系列之四
  7. Android 响应式编程框架 - RxJava2(二)基础
  8. Android开机自启动程序设置及控制方法思
  9. Android Studio中genymotion安装方法
  10. Android中实现java与PHP服务器(基于新浪云