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;多截取一个
if (nn <= length) {//如果还有汉字,那么继续开启线程,相当于递归的感觉
startTv(nn);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
).start();
}
public class TiaoZiActivity extends Activity {
private TextView textView;
private String s = "天生我才必有用,千金散盡還福來--李白\n你挑著但,我騎著馬--唐僧\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);//调用构造方法,直接开启
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
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;//间隔时间
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;多截取一个
if (nn <= length) {//如果还有汉字,那么继续开启线程,相当于递归的感觉
startTv(nn);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
).start();
}
}
<?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>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有