欢迎访问 生活随笔!

尊龙游戏旗舰厅官网

当前位置: 尊龙游戏旗舰厅官网 > 运维知识 > android >内容正文

android

android 中文 api —— textswitcher -尊龙游戏旗舰厅官网

发布时间:2025/1/21 android 5 豆豆
尊龙游戏旗舰厅官网 收集整理的这篇文章主要介绍了 android 中文 api —— textswitcher 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

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)

         使用提供的contextattributes来创建一个空的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的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得尊龙游戏旗舰厅官网网站内容还不错,欢迎将尊龙游戏旗舰厅官网推荐给好友。

网站地图