TextSwitcher 字面理解是文字交换器,是ViewSwitcher的子类,从ViewSwitcher来看,是View交换器,TextSwitcher继承自ViewSwitcher,显然是交换TextView。

点击缓慢出现文字

BaseActivity
package com.shaoxin.mytextswitcher;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity; /**
* Created by shaoxin on 2016/12/4.
*/ public abstract class BaseActivity extends AppCompatActivity {
public abstract void init(); public abstract void listener(); @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
listener();
}
}
MainActivity
package com.shaoxin.mytextswitcher;

import android.os.Bundle;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher; public class MainActivity extends BaseActivity {
private TextSwitcher textswitcher;
private Button btn;
private ViewSwitcher.ViewFactory factory; @Override
public void init() {
setContentView(R.layout.activity_main);
textswitcher = (TextSwitcher) findViewById(R.id.textswitcher);
btn = (Button) findViewById(R.id.btn);
} @Override
public void listener() {
factory = new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
TextView textView = new TextView(MainActivity.this);
textView.setTextSize(40);
return textView;
}
};
textswitcher.setFactory(factory);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textswitcher.setInAnimation(AnimationUtils
.loadAnimation(MainActivity.this, android.R.anim.fade_in));
textswitcher.setInAnimation(AnimationUtils
.loadAnimation(MainActivity.this, android.R.anim.fade_out));
textswitcher.setText("hello");
}
});
} @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.shaoxin.mytextswitcher.MainActivity"> <Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="点击出现" /> <TextSwitcher
android:id="@+id/textswitcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/> </LinearLayout>

TextSwitcher 简单用例的更多相关文章

  1. extern外部方法使用C#简单样例

    外部方法使用C#简单样例 1.添加引用using System.Runtime.InteropServices; 2.声明和实现的连接[DllImport("kernel32", ...

  2. spring事务详解(二)简单样例

    系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...

  3. Docker Compose 创建yml 简单试例

    Docker Compose 创建yml 简单试例 Docker Compose 文件使用格式版本需要与Docker版本对应可在官网内查找 查找地址:https://docs.docker.com/c ...

  4. webpack -- 多页面简单小例

    有时单页面并不能满足我们的业务需求,就需要去构建多页面应用,以下为简单小例: entry:{ index:'./src/module/index/index.js', student:'./src/m ...

  5. velocity简单样例

    velocity简单样例整体实现须要三个步骤,详细例如以下: 1.创建一个Javaproject 2.导入须要的jar包 3.创建须要的文件 ============================= ...

  6. 自己定义隐式转换和显式转换c#简单样例

    自己定义隐式转换和显式转换c#简单样例 (出自朱朱家园http://blog.csdn.net/zhgl7688) 样例:对用户user中,usernamefirst name和last name进行 ...

  7. php libevent扩展的简单用例

    php libevent扩展具有很强大的功能.以下摘自百度百科: Libevent 是一个用C语言编写的.轻量级的开源高性能网络库,主要有以下几个亮点:事件驱动( event-driven),高性能; ...

  8. VC6 鼠标钩子 最简单样例

    Windows系统是建立在事件驱动的机制上的,说穿了就是整个系统都是通过消息的传递来实现的.而钩子是Windows系统中非常重要的系统接口,用它能够截获并处理送给其它应用程序的消息,来完毕普通应用程序 ...

  9. gtk+3.0的环境配置及基于gtk+3.0的python简单样例

    /*********************************************************************  * Author  : Samson  * Date   ...

随机推荐

  1. 大二在CSDN的博客整理

    001我为什么想写博客 控制台版2048 version_1.0总结 022 囚徒困境中的均衡-----从一篇经典论文说起 021 模拟退火算法学习(一)-----求解最短连通路径 020 小记一次网 ...

  2. 聊聊HTTPS和SSL/TLS协议

    要说清楚 HTTPS 协议的实现原理,至少需要如下几个背景知识.1. 大致了解几个基本术语(HTTPS.SSL.TLS)的含义2. 大致了解 HTTP 和 TCP 的关系(尤其是“短连接”VS“长连接 ...

  3. 个人学习记录1:二维数组保存到cookie后再读取

    二维数组保存到cookie后再读取 var heartsArray = [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0, ...

  4. python:mysql+pycharm+Django环境搭建

    1.安装mysql-python 环境:OS X Yosemite10.10.2 + Python2.7 首先网上搜了下mysql-python,说要先安装mysql客户端,然后改配置文件,可是各种改 ...

  5. win7挂载VHD文件,模拟多系统并存

    挂载vhd是win7 一个很特殊的功能,xp不能支持,一些服务器版的系统 像2008.2008R2这些可能也是支持的,只是没有测试过. 提前的准备: Win7  wim 镜像文件 Imagex.exe ...

  6. 关于当传过来的值转换成string类型报错的问题

    有时候直接写 string str=request.param["str"].tostring;会报错,是因为接受到的值可能是空的 这个时候就可以这样写 string _actio ...

  7. PHP保留2位小数 格式化小数、浮点数

    JS保留两位小数例子 四舍五入使用函数 toFixed() <html> <head> </head> <script language="java ...

  8. 第2月第5天 arc invocation getReturnValue

    http://blog.csdn.net/zengconggen/article/details/38024625

  9. composer的安装以及laravel框架的安装(一)

    laravel号称世界上最好的php框架,没有之一,下面介绍它的安装 laravel学习交流qq群:293798134 composer的安装 : php开发者很多,并且在web开发领域占据绝对统治地 ...

  10. exception catch doesn't work?? (python 3)

    exception catch doesn't work?? (python 3) except u.URLError, e: ^ SyntaxError: invalid syntax in Pyt ...