日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

TextSwitcher--文本切换器

發布時間:2024/4/14 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TextSwitcher--文本切换器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

圖片的切換可以使用ImageSwitcher實現,文本的切換動畫也是有一個叫TextSwitcher的類可以做到,他們都繼承ViewSwitcher類。

ViewSwitcher 僅僅包含子類型TextView。TextSwitcher被用來使屏幕上的label產生動畫效果。每當setText(CharSequence)被調用時,TextSwitcher使用動畫方式將當前的文字內容消失并顯示新的文字內容。

package com.shao.act; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.TextSwitcher; import android.widget.TextView; import android.widget.ViewSwitcher.ViewFactory; public class TextSwitcherActivity extends Activity implements ViewFactory{ /** Called when the activity is first created. */ TextSwitcher switcher; Handler handler; String [] resources={ " ","身是菩提樹,", "心如明鏡臺,", "時時勤拂拭,", "勿使惹塵埃。" }; private Handler mHandler = new Handler(){ public void handleMessage(Message msg) { switch (msg.what) { case 1: id = next(); //更新Id值 updateText(); //更新TextSwitcherd顯示內容; break; } }; }; int id= 0; //resources 數組的Id; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); Timer timer = new Timer(); timer.scheduleAtFixedRate(new MyTask(), 1, 3000);//每3秒更新 } private void init(){ switcher = (TextSwitcher) findViewById(R.id.switcher); switcher.setFactory(this); switcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); switcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); } private int next(){ int flag = id+1; if(flag>resources.length-1){ flag=flag-resources.length; } return flag; } private void updateText(){ switcher.setText(resources[id]); } @Override public View makeView() { // TODO Auto-generated method stub TextView tv =new TextView(this); tv.setText(resources[id]); return tv; } private class MyTask extends TimerTask{ @Override public void run() { Message message = new Message(); message.what = 1; mHandler.sendMessage(message); } } }


總結

以上是生活随笔為你收集整理的TextSwitcher--文本切换器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。