2
我是新手。試圖做我的第一場比賽。我需要拖延透明PNG到我的畫布,但似乎不能正確。我需要在畫布上延遲繪圖
public LessonsMain(Context context) {
super(context);
// TODO Auto-generated constructor stub
mFujiSensei = getResources().getDrawable(R.drawable.old_man_fuji);
mFujiSensei.setBounds(0,0,mFujiSensei.getIntrinsicWidth(),mFujiSensei.getIntrinsicHeight());
mBackground = getResources().getDrawable(R.drawable.lessons_background);
mBackground.setBounds(0,0,mBackground.getIntrinsicWidth(),mBackground.getIntrinsicHeight());
}
@Override
protected void onDraw(final Canvas canvas) {
super.onDraw(canvas);
mBackground.draw(canvas);
TimerTask task = new TimerTask() {
public void run(){
mFujiSensei.draw(canvas);
}
}; timer.schedule(task, 3000);
}
對不起仍然沒有得到它。我試着把它放在不同的線程中,但它仍然不起作用。
public class LessonsMain extends View{
Drawable mBackground;
Drawable mFujiSensei;
Timer timer;
Handler handler;
Runnable runnable;
public LessonsMain(Context context) {
super(context);
// TODO Auto-generated constructor stub
mFujiSensei = getResources().getDrawable(R.drawable.old_man_fuji);
mFujiSensei.setBounds(0,0,mFujiSensei.getIntrinsicWidth(),mFujiSensei.getIntrinsicHeight());
mBackground = getResources().getDrawable(R.drawable.lessons_background);
mBackground.setBounds(0,0,mBackground.getIntrinsicWidth(),mBackground.getIntrinsicHeight());
}
@Override
protected void onDraw(final Canvas canvas) {
super.onDraw(canvas);
mBackground.draw(canvas);
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
TimerTask task = new TimerTask() {
public void run(){
mFujiSensei.draw(canvas);
}
}; timer.schedule(task, 3000);
}
}).start();
}
}
好的,謝謝,我會試試看。 – kishfoo