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 ...
随机推荐
- 彻底删除MySQL
安装mysql数据库.最后一步APPLY SECURITY SETTINGS总是失败.感觉很郁闷.上网找了教程,有前四步,一一做了,发现还是不对.最近突然发现在环境变量那边的路径还没有卸载干净.可能我 ...
- poj3468 A Simple Problem with Integers(zkw区间修改模板)
此题是一道线段树的裸题,这里只是为了保存我的zkw线段树模板 #include <cstdio> #include <cstring> #include <iostrea ...
- 回归树|GBDT|Gradient Boosting|Gradient Boosting Classifier
已经好久没写了,正好最近需要做分享所以上来写两篇,这篇是关于决策树的,下一篇是填之前SVM的坑的. 参考文献: http://stats.stackexchange.com/questions/545 ...
- Javascript实现前端简单路由
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http ...
- 机器学习中的相似性度量(Similarity Measurement)
机器学习中的相似性度量(Similarity Measurement) 在做分类时常常需要估算不同样本之间的相似性度量(Similarity Measurement),这时通常采用的方法就是计算样本间 ...
- Spring系列之依赖注入的方式
一.依赖注入方式 对于spring配置一个bean时,如果需要给该bean提供一些初始化参数,则需要通过依赖注入方式,所谓的依赖注入就是通过spring将bean所需要的一些参数传递到bean实例对象 ...
- java读取项目根路径下和任意磁盘位置下的properties文件
1.读取项目根路径下的properties文件比较简单也是比较常见的一种操作. 具体代码如下: package com.xuanen.util; import java.util.Properties ...
- idea导入maven项目,web browser远程单步调试
问题:之前用idea14.1.3导入maven项目后,maven的dependencies不能自动解决依赖,到处都是红色的红线,看着就受不了.虽然不影响命令行编译,但是看着实在是不爽.总结下面几小步: ...
- Chrome 用户数据配置文件夹保存路径在哪?(Mac OS X/Windows/Linux)
在重装系统之前都想要对 Chrome 中的数据进行备份,以能够在重装系统后恢复这些数据.但是除了一些玩 Chrome 很长时间的用户,鲜有人知道 Chrome 的用户数据到底保存在什么地方.如果你也有 ...
- Linux C 字符串输入函数 gets()、fgets()、scanf() 详解
一.gets() 函数详解 gets()函数用来从 标准输入设备(键盘)读取字符串直到 回车结束,但回车符('\n')不属于这个字符串. 调用格式为: gets(str); 其中str为字符串变量(字 ...