2013-04-07 2 views
0

로드해야하는 이미지가 4 개 있습니다. 하나의 애니메이션을 재생하고, 500ms를 기다린 다음, 500ms를 기다린 후, 500ms를 기다려야합니다. 모든 애니메이션은 알파를 255에서 0으로 변경 한 다음 255로 변경합니다. 모든 네 가지 imageView에는 해당 애니메이션이 필요합니다.Android ImageView changing alpha 애니메이션

현재 두 가지 문제가 있습니다.

1) 1. 모든 이미지가 동시에 재생됩니다.
) 다음에 메서드가 호출 될 때 애니메이션이 작동하지 않습니다. 이것이 가장 우아한 해결책 경우

public void computerLights() 
{ 

    ImageView green = (ImageView)findViewById(R.id.imgViewGreen); 
    ImageView red = (ImageView)findViewById(R.id.imgViewRed); 
    ImageView blue = (ImageView)findViewById(R.id.imgViewBlue); 
    ImageView yellow = (ImageView)findViewById(R.id.imgViewYellow); 

    AlphaAnimation transparency = new AlphaAnimation(1, 0); 

    transparency.setDuration(500); 
    transparency.start(); 
    green.startAnimation(transparency); 
    red.startAnimation(transparency); 
    blue.startAnimation(transparency); 
    yellow.startAnimation(transparency); 
} 

답변

0

는 잘 모르겠지만, 당신은 당신은 500ms 간격으로 메시지를 보낼 수있는 핸들러 꽤 쉽게 달성 할 수있다.

private int mLights = new ArrayList<ImageView>(); 
private int mCurrentLightIdx = 0; 
private Handler mAnimationHandler = new Handler(){ 

    @Override 
    public void handleMessage(Message msg) { 
     super.handleMessage(msg); 

     ImageView currentLightIdx = mLights.get(currentLight); 

     AlphaAnimation transparency = new AlphaAnimation(1, 0); 

     transparency.setDuration(500); 
     transparency.start(); 
     currentLight.startAnimation(transparency); 

     currentLightIdx++; 
     if(currentLightIdx < mLights.size()){ 
      this.sendMessageDelayed(new Message(), 500); 
    } 
}; 

public void computerLights() 
{ 

    ImageView green = (ImageView)findViewById(R.id.imgViewGreen); 
    ImageView red = (ImageView)findViewById(R.id.imgViewRed); 
    ImageView blue = (ImageView)findViewById(R.id.imgViewBlue); 
    ImageView yellow = (ImageView)findViewById(R.id.imgViewYellow); 

    mLights.add(green); 
    mLights.add(red); 
    mLights.add(blue); 
    mLights.add(yellow); 

    mAnimationHandler.sendMessage(new Message()); 
} 

첫 번째 메시지를 보낸 후에 처리기는 모든 애니메이션이 시작될 때까지 500ms마다 메시지를 계속 보냅니다.

관련 문제