<?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. Android实现弹出Toast提示
  2. 重写对话框
  3. android GestureDetector 基于webview的手势滑动实现
  4. Android--第一行代码笔记(2)
  5. ListView的使用
  6. Android(安卓)ListView用法(1),不用ListActivity实现
  7. android的ViewFlipper
  8. 重写EditText回车键跳到下一个EditText
  9. loading android

随机推荐

  1. 联邦计算:不暴露真实数据如何完成合作建模
  2. 腾讯云Elasticsearch集群规划及性能优化
  3. 降本提效,贝壳搜索推荐架构统一之路
  4. 实现全托管,腾讯云服务网格的架构演进
  5. Linux之文本处理的练习
  6. 动态记忆网络:向通用NLP更近一步
  7. 深入理解Java的接口和抽象类
  8. zabbix yum及package模块
  9. 图解 Java 中的数据结构及原理,不懂的也能
  10. 致老男孩教育的维权声明 - Spug运维