2019独角兽企业重金招聘Python工程师标准>>>

声明

  欢迎转载,但请保留文章原始出处:)

    madgoat:http://madgoat.cn/

    博客园:http://www.cnblogs.com

    农民伯伯: http://www.cnblogs.com/over140/

版本

  Android 2.2 r1

正文

  一、结构

    public class TextSwitcher extends ViewSwitcher

    java.lang.Object

      android.view.View

        android.view.ViewGroup

          android.widget.FrameLayout

  android.widget.ViewAnimator

  android.widget.ViewSwitcher

  android.widget.TextSwitcher

  二、类概述

    

    ViewSwitcher仅仅包含子类型TextView。TextSwitcher被用来使屏幕上的label产生动画效果。每当setText(CharSequence)被调用时,TextSwitcher使用动画方式将当前的文字内容消失并显示新的文字内容。(译者注:改变文字时增加一些动画效果)

  三、构造函数

public TextSwitcher (Context context)

创建一个新的空TextSwitcher

参数

context 应用程序上下文

public TextSwitcher (Context context, AttributeSet attrs)

使用提供的context和attributes来创建一个空的TextSwitcher

参数

context 应用程序环境

attrs                   属性集合

  四、公共方法

public void addView (View child, int index, ViewGroup.LayoutParams params)

根据指定的布局参数新增一个子视图

参数

child          新增的子视图

index         新增子视图的位置

params    新增子视图的布局参数

抛出异常

IllegalArgumentException       当子视图不是一个TextView实例时

public void setCurrentText (CharSequence text)

设置当前显示的文本视图的文字内容。非动画方式显示。

参数

text           需要显示的新文本内容

public void setText (CharSequence text)

设置下一视图的文本内容并切换到下一视图。可以动画的退出当前文本内容,显示下一文本内容。

参数

text           需要显示的新文本内容

  五、代码示例

    5.1  摘自APIDemos->View->TextSwitcher

      5.1.1  Java

public class TextSwitcher1 extends Activity implements ViewSwitcher.ViewFactory,
        View.OnClickListener {

private TextSwitcher mSwitcher;

private int mCounter = 0;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

setContentView(R.layout.text_switcher_1);

mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
        mSwitcher.setFactory(this);

Animation in = AnimationUtils.loadAnimation(this,
                android.R.anim.fade_in);
        Animation out = AnimationUtils.loadAnimation(this,
                android.R.anim.fade_out);
        mSwitcher.setInAnimation(in);
        mSwitcher.setOutAnimation(out);

Button nextButton = (Button) findViewById(R.id.next);
        nextButton.setOnClickListener(this);

updateCounter();
    }

public void onClick(View v) {
        mCounter++;
        updateCounter();
    }

private void updateCounter() {
        mSwitcher.setText(String.valueOf(mCounter));
    }

public View makeView() {
        TextView t = new TextView(this);
        t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
        t.setTextSize(36);
        return t;
    }
}

      5.1.2  XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<Button android:id="@+id/next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="@string/text_switcher_1_next_text" />

<TextSwitcher android:id="@+id/switcher"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

    5.2  其他示例

      http://tech.ddvip.com/2010-02/1265125017144500.html

      http://www.javaeye.com/topic/569985

  六、下载

    CSDN:http://download.csdn.net/source/2774515

结束

   madgoat非常积极,接到本章译稿后就迅速的翻译出来,并且附带完善的代码和截图,现在已经在翻译下一篇译稿,感谢他如此积极参与!

转载于:https://my.oschina.net/sunxichao/blog/346149

Android 中文 API —— TextSwitcher相关推荐

  1. Android 中文API (94) —— MediaController

    前言 本章内容是android.widget.MediaController,版本为Android 2.3 r1,翻译来自"唐明",再次感谢"唐明" !期待你一 ...

  2. Android 中文 API 文档 (45) —— AbsoluteLayout.LayoutParams

    前言 本章内容是 android.widget.AbsoluteLayout.LayoutParams,版本为Android 2.2 r1,翻译来自"绵白糖",再次感谢" ...

  3. Android 中文API (92) —— MenuInflater

    前言 本章内容是android.view.MenuInflater,版本为Android 2.3 r1,翻译来自"獨鍆躌踄",欢迎大家访问他的博客:http://www.cnblo ...

  4. Android 中文 API (90) —— WindowManager

    一.结构 public interface WindowManager extends android.view.ViewManager android.view.WindowManager 二.概述 ...

  5. Android 中文API (70) —— BluetoothDevice[蓝牙]

    前言 本章内容是 android.bluetooth.BluetoothDevice,为Android蓝牙部分的章节翻译.蓝牙设备类,代表了蓝牙通讯国足中的远端设备.版本为 Android 2.3 r ...

  6. Android中文API(127) —— MessageQueue

    结构 继承关系 public class MessageQueue extends Object java.lang.Object android.os.MessageQueue 类概述 保存消息列表 ...

  7. android 中文 API (41) —— RatingBar.OnRatingBarChangeListener

    前言 本章内容是 android.widget.RatingBar.OnRatingBarChangeListener,版本为Android 2.2 r1,翻译来自madgoat,欢迎大家访问他的博客 ...

  8. Android 中文API (91) —— GestureDetector

    前言 本章内容是android.view.GestureDetector,版本为Android 2.3 r1,翻译来自"Haiya 胡蝶",再次感谢"Haiya 胡蝶&q ...

  9. Android 中文 API (93) —— BaseExpandableListAdapter

    前言 本章内容是android.widget.BaseExpandableListAdapter,版本为Android 2.3 r1,翻译来自"天涯明月刀",欢迎大家访问他的博客: ...

最新文章

  1. 计算机专业知识认识报告,计算机专业认识习报告.doc
  2. echarts 在两点之间画一条线_凭什么?辛辛苦苦画了三个小时,却换来一句“撕了重画”...
  3. C#之windows桌面软件第九课:汉字串口助手
  4. 出块过程 (1)close发送消息
  5. Calendar的那些神坑
  6. 常见的四种文本自动分词详解及IK Analyze的代码实现
  7. Hyperledger Fabric Endorsement policies——背书策略
  8. 黑苹果显卡加速_谁说苹果macOS系统不适合3D,没有OC渲染器?
  9. PADS软件如何导出BOM
  10. navicat15 安装
  11. python图片灰度化处理
  12. Cloud Control 12c Installation 错误处理 Checking swap space: 0 MB available, 150 MB required. Failed
  13. 任鑫:提前布局,不做轻公司
  14. leetcode79 word serach 解题报告
  15. 禅修程序员十诫 [译文]
  16. INTEL CPU 内核漏洞问题该如何处理?
  17. 运用Python爬虫爬取一个美女网址,爬取美女图
  18. matlab中P代码即P文件加密与逆向工程探讨
  19. JavaScript异步与同步解析
  20. 用html做七巧板的方法,纯HTML5绘制的七巧板

热门文章

  1. java父进程获取子进程异常_如何在perl的父进程中获取死亡的子进程的PID?
  2. 激光SLAM学习--数据处理和特征提取
  3. 北斗导航 | GPS原理与接收机设计——青冥剑(金码、C/A码、P码)
  4. php新手最容易犯的错误,学习PHP过程中容易犯的一些错误
  5. 想要成为软件开发中的王者,需要明白的 21 条准则
  6. 十年的老代码,你敢动?
  7. c语言为什么数据写不进文件,求大神看看为什么不能将数据写入文件
  8. php 字符串截取_网络安全WEB之PHP代码审计,攻防世界题目warmup
  9. 基于android的考勤定位算法,基于移动定位服务的考勤管理系统
  10. json支持的最大长度_Swifter.Json 可能是 .Net 平台迄今为止性能最佳的 Json 序列化库【开源】...