TextSwitcher 简单用例
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 简单用例的更多相关文章
- extern外部方法使用C#简单样例
外部方法使用C#简单样例 1.添加引用using System.Runtime.InteropServices; 2.声明和实现的连接[DllImport("kernel32", ...
- spring事务详解(二)简单样例
系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...
- Docker Compose 创建yml 简单试例
Docker Compose 创建yml 简单试例 Docker Compose 文件使用格式版本需要与Docker版本对应可在官网内查找 查找地址:https://docs.docker.com/c ...
- webpack -- 多页面简单小例
有时单页面并不能满足我们的业务需求,就需要去构建多页面应用,以下为简单小例: entry:{ index:'./src/module/index/index.js', student:'./src/m ...
- velocity简单样例
velocity简单样例整体实现须要三个步骤,详细例如以下: 1.创建一个Javaproject 2.导入须要的jar包 3.创建须要的文件 ============================= ...
- 自己定义隐式转换和显式转换c#简单样例
自己定义隐式转换和显式转换c#简单样例 (出自朱朱家园http://blog.csdn.net/zhgl7688) 样例:对用户user中,usernamefirst name和last name进行 ...
- php libevent扩展的简单用例
php libevent扩展具有很强大的功能.以下摘自百度百科: Libevent 是一个用C语言编写的.轻量级的开源高性能网络库,主要有以下几个亮点:事件驱动( event-driven),高性能; ...
- VC6 鼠标钩子 最简单样例
Windows系统是建立在事件驱动的机制上的,说穿了就是整个系统都是通过消息的传递来实现的.而钩子是Windows系统中非常重要的系统接口,用它能够截获并处理送给其它应用程序的消息,来完毕普通应用程序 ...
- gtk+3.0的环境配置及基于gtk+3.0的python简单样例
/********************************************************************* * Author : Samson * Date ...
随机推荐
- git版本控制?
git是一个分布式的版本控制系统,版本控制系统,类似于保险箱,而我们的代码就是资产:通过对代码的有效管理可以更好的提高我们的生产效率:maven是主要是一个项目构建工具,解决的是我们个人在开发过程中的 ...
- python异常处理
1. 异常 (1) 异常处理 #没有异常处理 num = int('abc') print(num) #报错 #异常处理 try: num = int('abc') #try里的代码是受保护的 pri ...
- Canvas绘制渐变
1.绘制线性渐变 Canvas提供了用于创建线性渐变的函数createLinearGradient(x0,y0,x1,y1),坐标点(x0,y0)是起点 ,(x1,y1)是终点 创建一个渐变色 var ...
- HTML5的属性
一.全局属性 1.class属性 class属性对元素指定CSS类选择器 <!doctype html> <html> <meta charset="utf-8 ...
- js中的逻辑与(&&)和逻辑或(||)
之前有一个同事去面试,面试过程中碰到这样一个问题: 在js中写出如下的答案 : var a = 2; var b = 3; var andflag = a && b ; var orf ...
- 用 const 还是用 let?
ES6 里新增了两种声明变量的方式,let 和 const,加上原来的 var,一共就有三种方式来声明变量了.那到底该用哪个呢?关于“尽可能不用 var” 这一点,大家应该没有什么意见分歧(其实还是有 ...
- Ubuntu 12.4 Apache2 安装教程
一.更新操作系统 sudo apt-get update && sudo apt-get upgrade 二.安装Apache及依赖 sudo apt-get install apac ...
- 【Alpha版本】 第三天 11.9
一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 注册界面的实现 填写招聘时用户填写各个日期到可以使用工具方便选择日 ...
- 逻辑思维面试题-java后端面试-遁地龙卷风
(-1)写在前面 最近参加了一次面试,对笔试题很感兴趣,就回来百度一下.通过对这些题目的思考让我想起了建模中的关联,感觉这些题如果没接触就是从0到1,考验逻辑思维的话从1到100会更好,并且编程简易模 ...
- php之获取程序源码的方法
文件hello.php和index.php在同一目录 hello.php <?php class hello{ public function __construct() { echo 'hel ...