今天调查怎么实现在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);
}

}

}

更多相关文章

  1. Android(安卓)自定义View之View的绘制
  2. Android实例练习-可爱的小闹钟
  3. Linux设置qt-android开发环境
  4. Android39_Clock和TimePicker
  5. Android(安卓)Material Design之CardView(卡片式布局)
  6. android 7.0 有关wifi热点设置信息
  7. 二、Toolbar
  8. Android(安卓)GLSurfaceView详解
  9. Android(安卓)TextView部分文字实现点击事件

随机推荐

  1. Android(安卓)PinnedHeaderListView 详解
  2. Android(安卓)Support兼容包详解
  3. 深度解析Android中字体设置
  4. Android: 如何创建AVD以及选择合适target
  5. android 电容屏(一):电容屏基本原理篇
  6. 专家专栏:Android层次化安全架构及核心组
  7. Spring for Android(安卓)探究
  8. android中activity全屏的方法
  9. Android(安卓)Shape
  10. Android第一行代码笔记