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. NodeJs + mongodb模块demo

    代码比较通俗易懂,但是我还是在这个过程中浪费了不少时间,也算是看到了nodejs中异步的一个小坑.未来的坑还有很多,慢慢找坑填坑吧. 参考资料如下: 1.断言模块 : https://nodejs.o ...

  2. <<< java环境搭建

    先百度搜索"jdk下载"            安装完成之后,到系统环境变量设置(电脑右键,属性,高级系统设置) 然后点击下面path系统变量,把C:\Program Files ...

  3. elastichq auto connect

    $(document).ready(function () { $('#connectionURL').focus(); ajaxloading.hide(); scrollToTop.activat ...

  4. jquery实现简单瀑布流布局(续):图片懒加载

    # jquery实现简单瀑布流布局(续):图片懒加载 这篇文章是jquery实现简单瀑布流布局思想的小小扩展.代码基于前作的代码继续完善. 图片懒加载就是符合某些条件时才触发图片的加载.最常见的具体表 ...

  5. JS 加载html 在IE7 IE8下 可调试

    实际背景 就是都是HTML 公共头部底部  然后中间部分加载不同的HTML文件 有点跟模板引擎一样 jQuery 有个load函数 加载html文件的路径 获取html内容 到中间部分 正常下是不能用 ...

  6. rails 常用的知识点

    按惯例先上网址:  http://guides.ruby-china.org/    适合初学者很好的文章 ===========================知识点================ ...

  7. [UML]UML系列——用例图中的各种关系(include、extend)

    用例图中的各种关系 一.参与者与用例间的关联关系 参与者与用例之间的通信,也成为关联或通信关系. 二.用例与用例之间的关系 包含关系(include) 扩展关系(extend) 包含关系 (1)  概 ...

  8. 认识VTK工作原理

    VTk通过数据流实现变信息为图形数据的. 数据流一般为:source-filter--mapper--actor--render--renderwindow--interactor. 要理解工作原理, ...

  9. AndroidStudio导入Library

    1.把它像Module一样导入. File >New >ImportModule(选择你要导入的Library). 如果出现了下面的情况,意思是跟项目中的Module重名,改个名字就行了. ...

  10. Linux进程间通信(九):数据报套接字 socket()、bind()、sendto()、recvfrom()、close()

    前一篇文章,Linux进程间通信——使用流套接字介绍了一些有关socket(套接字)的一些基本内容,并讲解了流套接字的使用,这篇文章将会给大家讲讲,数据报套接字的使用. 一.简单回顾——什么是数据报套 ...