我想做一个动画,我有 10 个球的图像,我想做:
Image1
可见,所有其他图像隐藏Image2
可见所有其他隐藏的图像- ...
Image10
可见所有其他隐藏的图像
我应该在一个动画中做到这一点(如何?)还是应该创建一个 java 方法 showImage(String pathimage) 来显示位于 pathimage 的图像并隐藏其他的?我可以使用任何关于时间延迟的想法吗
handler.postDelayed(new Runnable() {
public void run() { }
}
编辑,这是我的代码 问题是 run() 总是在似乎是无限循环的情况下被调用。但我看不出我的错误在哪里
游戏活动
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
.....
ImageView image2 = (ImageView) findViewById(R.id.imageView3);
image2.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
myAsyncRunnable mar = new myAsyncRunnable(GameActivity.this);
mar.execute(null);
PhotoTask photoTask = new PhotoTask(camera,surfaceCamera,isPreview,holder,GameActivity.this);
photoTask.execute(null);
Log.w("GAMEACTIVITY","PHOTOTASK");
return false;
}
});
}
我的异步任务
public class myAsyncRunnable extends AsyncTask<Void, Boolean, Void> {
GameActivity gameactivity;
@Override
protected Void doInBackground(Void... params) {
pull();
return null;
}
public myAsyncRunnable(GameActivity gameactivity) {
super();
this.gameactivity = gameactivity;
}
public void pull() {
final ImageView image3 = (ImageView) gameactivity.findViewById(R.id.imageView3);
final int drawables[] = new int[] {R.drawable.pull2,R.drawable.pull3,R.drawable.pull4,R.drawable.pull5,R.drawable.pull6,R.drawable.pull7};
Runnable runnable = new Runnable() {
@Override
public void run() {
for (int i=0;i<drawables.length;i++) {
image3.setImageResource(drawables[i]);
gameactivity.handler.postDelayed(this, 500);
Log.w("asyncrunnable","run"+i);
}
}
};
gameactivity.handler.post(runnable);
}
}