国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android實(shí)現(xiàn)文字逐字顯示出來

2019-10-23 18:27:56
字體:
供稿:網(wǎng)友

先上Android實(shí)現(xiàn)文字逐字顯示出來效果圖,供大家參考,具體內(nèi)容如下

Android文字逐字顯示,Android文字一個(gè)個(gè)顯示,Android逐字顯示

可以采用自定義TextView的方式去實(shí)現(xiàn),也可才用定時(shí)更新文字顯示,思路是讓TextView每隔一秒顯示以一個(gè)字符串(并非每一秒多出來一個(gè)漢字),那么就簡(jiǎn)單了,可以開啟一個(gè)線程,那么線程主要方法如下:

public static void startTv(final int n) {  new Thread(      new Runnable() {        @Override        public void run() {          try {            final String stv = s.substring(0, n);//截取要填充的字符串            tv.post(new Runnable() {              @Override              public void run() {                tv.setText(stv);              }            });            Thread.sleep(time);//休息片刻            nn = n + 1;//n+1;多截取一個(gè)            if (nn <= length) {//如果還有漢字,那么繼續(xù)開啟線程,相當(dāng)于遞歸的感覺              startTv(nn);            }          } catch (InterruptedException e) {            e.printStackTrace();          }        }      }  ).start();}

完整代碼如下:

1.Activity

public class TiaoZiActivity extends Activity {  private TextView textView;   private String s = "天生我才必有用,千金散盡還福來--李白/n你挑著但,我騎著馬--唐僧/n年后打藍(lán)思科技卡死了減肥的 kjdsfkjsjkdsfj kjdflskjklfjsljdflsjkldfjsljdflsjdfkl";;  private TiaoZiUtil tiaoziUtil;  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_tiaozi);    textView = ((TextView) findViewById(R.id.tv_text));    tiaoziUtil = new TiaoZiUtil(textView, s, 100);//調(diào)用構(gòu)造方法,直接開啟  }  @Override  protected void onDestroy() {    super.onDestroy();  }}

2.工具類

public class TiaoZiUtil {  private static TextView tv;  private static String s;  private static int length;  private static long time;  static int n = 0;  private static int nn;  public TiaoZiUtil(TextView tv, String s, long time) {    this.tv = tv;//textview    this.s = s;//字符串    this.time = time;//間隔時(shí)間    this.length = s.length();    startTv(n);//開啟線程  }  public static void startTv(final int n) {    new Thread(        new Runnable() {          @Override          public void run() {            try {              final String stv = s.substring(0, n);//截取要填充的字符串              tv.post(new Runnable() {                @Override                public void run() {                  tv.setText(stv);                }              });              Thread.sleep(time);//休息片刻              nn = n + 1;//n+1;多截取一個(gè)              if (nn <= length) {//如果還有漢字,那么繼續(xù)開啟線程,相當(dāng)于遞歸的感覺                startTv(nn);              }            } catch (InterruptedException e) {              e.printStackTrace();            }          }        }    ).start();  }}

3.布局文件

<?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">  <TextView    android:id="@+id/tv_text"    android:layout_width="match_parent"    android:layout_height="200dp" />  <TextView    android:id="@+id/mytext"    android:layout_width="match_parent"    android:layout_height="200dp" /></LinearLayout>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 化德县| 武宁县| 文登市| 获嘉县| 福鼎市| 胶南市| 天水市| 潞城市| 抚顺县| 绩溪县| 滨海县| 英德市| 丰顺县| 汕尾市| 永顺县| 蒲城县| 朝阳区| 衡水市| 横峰县| 永丰县| 响水县| 深州市| 大兴区| 华容县| 东辽县| 聂拉木县| 成安县| 龙陵县| 巴彦县| 安岳县| 五河县| 马龙县| 鸡泽县| 印江| 公主岭市| 临西县| 博兴县| 万荣县| 谷城县| 阿合奇县| 蓝山县|