public class AnimImageView implements Runnable {
@Override
public void run() {
BterryAnim();
battery_image.postDelayed(animImageView, 1000);
}
public void BterryAnim() {
float[] stateArray = new float[] { 0.1f, 0.25f, 0.5f, 0.75f, 1f };
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.battery_full);
int height = bitmap.getHeight();
int width = bitmap.getWidth();
// 使用Matrix控制充电动画
Matrix matrix = new Matrix();
matrix.postScale(stateArray[state], 1.0f);
Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height,
matrix, false);
state = state + 1;
battery_image.setImageBitmap(newBitmap);
if (state == 5) {
state = 0;
}
}
为何可以在非ui线程中设置ImageView的setImageBitmap?
------解决思路----------------------
重点在 postDelayed
http://www.cr173.com/html/19165_1.html
------解决思路----------------------
楼上正解!!!