2012-05-31 7 views
0

화면에 이미지 세트가있는 앱을 만들려고합니다. 사용자가 이미지를 클릭 한 다음 휴대폰을 흔들면보기의 모든 이미지가 클릭 한 이미지를 제외한 화면에서 사라집니다.하나만 제외하고 모든 이미지가 동적으로 사라집니다.

// List of the Images for the app 
private ImageView image1, image2; 
private ImageView image3, image4; 
private ImageView image5, image6; 
private ImageView image7, image8; 
private ImageView image9, image10; 
private ImageView image11, image12; 

private ImageView selectedImage; 
private boolean flag = true; 

// an array that will hold all the images. 
private ImageView cards[] = new ImageView[12]; 

//SET THE IMAGES... 


// onShake 
mSensorListener 
     .setOnShakeListener(new ShakeEventListener.OnShakeListener() { 
       public void onShake() { 
       if (selectedImage != null) { 
        showSelectedImageOnly(); 
       } 
      } 
     }); 

private void showSelectedImageOnly() { 
    if(!flag) 
     return; 

    for (ImageView image : cards){ 
     if(image.getId() != selectedImage.getId()){ 
      image.setVisibility(View.INVISIBLE); 
      Log.d("--MY-APP", "image number "+image.getId()+" was deleted"); 
     } 
    } 
    flag = false; 
} 

@Override 
public void onClick(View v) { 
    switch (v.getId()) { 
    case R.id.ImageView01: 
     selectedImage = null; 
     selectedImage = image1; 
     rotateImage(0, image1, image2); 
     defineTrickCard(0); 
     break; 
    case R.id.ImageView02: 
     selectedImage = image1; 
     rotateImage(0, image1, image2); 
     defineTrickCard(0); 
     break; 
    case R.id.ImageView03: 
    // .... THIS GOES ON... 
    case R.id.ImageView12: 
     selectedImage = image11; 
     rotateImage(5, image11, image12); 
     defineTrickCard(5); 
     break; 
    } 
} 

private void rotateImage(int index, ImageView firstImage, 
     ImageView secondImage) { 
    if (isImages[index]) { 
     applyRotation(0, 90, firstImage, secondImage, isImages[index]); 
     isImages[index] = !isImages[index]; 

    } else { 
     applyRotation(0, -90, firstImage, secondImage, isImages[index]); 
     isImages[index] = !isImages[index]; 
    } 
} 

private void applyRotation(float start, float end, ImageView firstImage, 
     ImageView secondImage, boolean isFirst) { 
    // Find the center of image 
    final float centerX = firstImage.getWidth()/2.0f; 
    final float centerY = firstImage.getHeight()/2.0f; 

    // Create a new 3D rotation with the supplied parameter 
    // The animation listener is used to trigger the next animation 
    final Flip3dAnimation rotation = new Flip3dAnimation(start, end, 
      centerX, centerY); 
    rotation.setDuration(500); 
    rotation.setFillAfter(true); 
    rotation.setInterpolator(new AccelerateInterpolator()); 
    rotation.setAnimationListener(new DisplayNextView(isFirst, firstImage, 
      secondImage)); 

    if (isFirst) { 
     firstImage.startAnimation(rotation); 
    } else { 
     secondImage.startAnimation(rotation); 
    } 

} 

문제가, 클릭있어 모든 이미지가보기에 남아와 사용자가 하나 개 이상의 이미지를 클릭 할 때 있고 전화가 진탕 도착 그 후 나머지는 사라한다 : 이것은 내가 지금까지 쓴 것입니다 필요에 따라

이 문제를 해결하는 방법에 대한 의견이 있으십니까? 내가 선택한 모든 선택되지 않은 (이전 선택 포함) 화면에서 사라지게해야합니다.

UPDATE :

rotateImage 기능을 보여주기 위해 코드를 업데이트, 3 차원 애니메이션에 대한 코드의 나머지 부분이 very good tutorial에서 가져온 것입니다.

답변

0

rotateImage 방법으로 이미지를 회전하려면 Animation을 사용하고있는 것 같습니다. 애니메이션의 경우 주목해야 할 점은 View 오브젝트가 애니메이션 중에 변경되지 않는다는 것입니다. 따라서보기를 숨기도록 설정해야하는 경우 onAnimationEnd 이벤트에 등록하고 view.setVisibility(View.INVISIBLE)으로 전화해야합니다.

+0

[이 튜토리얼] (http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html)을 사용하고 있으며 이미지의 전환이 마지막에 있습니다. 회전의. – thepoosh

+0

'rotateImage' 메소드의 코드를 게시 할 수 있습니까? 원래 질문을 업데이트 할 수 있습니다. – Rajesh

+0

원래 질문을 업데이트했습니다. – thepoosh

관련 문제