android通过线程实现逐行显示信息
今天调查怎么实现在android 手机上逐行显示内容的效果。这是其中的一种方法,通过AlphaAnimation来和设置线程的延时做的,效果可以实现,但开销比较大。开销小的方法将在下一篇文章中介绍。
package com.display;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.TextView;
public class Display extends Activity {
private TextView[] tvs = new TextView[7];
private Handler handler = new Handler();
private Button btnReload;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tvs[0] = (TextView) findViewById(R.id.TextView01);
tvs[1] = (TextView) findViewById(R.id.TextView02);
tvs[2] = (TextView) findViewById(R.id.TextView03);
tvs[3] = (TextView) findViewById(R.id.TextView04);
tvs[4] = (TextView) findViewById(R.id.TextView05);
tvs[5] = (TextView) findViewById(R.id.TextView06);
tvs[6] = (TextView) findViewById(R.id.TextView07);
loadContent();
btnReload = (Button) findViewById(R.id.Button01);
btnReload.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
loadContent();
}
});
}
private void loadContent() {
setInvisible();
for (int j = 0; j < tvs.length; j++) {
final TextView tv = tvs[j];
Runnable r = new Runnable() {
@Override
public void run() {
setAnimation(tv);
}
};
// 设置动画延时
handler.postDelayed(r, j * 1000);
}
}
// 设置动画
private void setAnimation(final TextView tv) {
AlphaAnimation aa = new AlphaAnimation(0, 1.0f);
aa.setDuration(1000);
aa.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
tv.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
});
tv.startAnimation(aa);
}
private void setInvisible() {
for (int i = 0; i < tvs.length; i++) {
tvs[i].setVisibility(View.INVISIBLE);
}
}
}
更多相关文章
- Android(安卓)自定义View之View的绘制
- Android实例练习-可爱的小闹钟
- Linux设置qt-android开发环境
- Android39_Clock和TimePicker
- Android(安卓)Material Design之CardView(卡片式布局)
- android 7.0 有关wifi热点设置信息
- 二、Toolbar
- Android(安卓)GLSurfaceView详解
- Android(安卓)TextView部分文字实现点击事件