2014-03-30 5 views
-1

이것은 내 코드이며 비트 맵을 사용하여 내 배경에 애니메이션을 추가하려고합니다! !! 모든 것을 움직일 수 있지만 문제는 특정 후 특정 이미지를 시작하는 방법을 모른다는 것입니다. 시간. 모든 비트 맵 이미지 (heartfal, heartfal1, heartfal2, heartfal3)가 동시에 시작됩니다. 특정 bmp 이미지를위한 타이머를 설정해야하므로 다른 이미지보다 몇 초 후에 시작할 수 있습니다. 그리고 또한 모든 bmp 이미지는 맨 위에서부터 시작됩니다 .. !! 나는 어딘가에서 시작하는 데 필요한 몇 가지 이미지> 높이를 변경하려면 모르겠다> 위치를 변경할 수 있지만 "움직이는 y"메신저 대신 "40"(말)주고 bmp 이미지가 움직이지 않습니다 .. 여전히 satnding 새로운 동일한 "40"position..Iam이 PLZ 사전안드로이드에서 비트 맵으로 타이머를 설정하는 방법

public class Mybringback extends View { 
     Bitmap heartsfal; 
     Bitmap heartsfal2; 
     Bitmap heartsfal3; 
     Bitmap heartsfal4; 
     float changingY; 

     public Mybringback(Context context, AttributeSet attrs) { 
      super(context); 

      heartsfal = BitmapFactory.decodeResource(getResources(), 
        R.drawable.animation1); 
      heartsfal2 = BitmapFactory.decodeResource(getResources(), 
        R.drawable.animation2); 
      heartsfal3 = BitmapFactory.decodeResource(getResources(), 
        R.drawable.animation3); 
      heartsfal4 = BitmapFactory.decodeResource(getResources(), 
        R.drawable.animation4); 
      changingY = 0; 

     } 

     @Override 
     protected void onDraw(Canvas canvas) { 
      super.onDraw(canvas); 

      canvas.drawBitmap(heartsfal, 20, changingY, null); 
      if (changingY < canvas.getHeight()) { 
       changingY += 1; 
      } else { 
       changingY = 0; 
      } 
      canvas.drawBitmap(heartsfal2, 120, changingY, null); 
      if (changingY < canvas.getHeight()) { 
       changingY += 1; 
      } else { 
       changingY = 0; 
      } 
      canvas.drawBitmap(heartsfal3, 260, changingY, null); 
      if (changingY < canvas.getHeight()) { 
       changingY += 1; 
      } else { 
       changingY = 0; 
      } 
      canvas.drawBitmap(heartsfal4, 400, changingY, null); 
      if (changingY < canvas.getHeight()) { 
       changingY += 1; 
      } else { 
       changingY = 0; 
      } 

      invalidate(); 
     } 
    } 

답변

0
private ScheduledThreadPoolExecutor execAds = null; 

private void startCheckTimer() { 
     execAds = new ScheduledThreadPoolExecutor(1);  
     execAds.scheduleAtFixedRate(new MyTaskAds(), 0, 10, TimeUnit.MILLISECONDS); 
    } 

private class MyTaskAds implements Runnable { 

     @Override 
     public void run() { 
      changingY += 1; 
      invalidate(); 
     } 
    } 

전화 startCheckTimer()에서 .. !! 감사합니다 도움을 안드로이드, changingY 이동합니다 .... (변경 시간 지연 원하는 경우 .)

관련 문제