0
에서 roatating 이미지에서 코드 예제를 수정 : 한 번 이미지를 클릭하면 안드로이드 : 내가 성공하지 노력하고 루프
http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html
는 그래서, 루프에서 이미지를 회전합니다. (두 번째 클릭은 일시 정지해야 함).핸들러와 스레딩을 사용해 보았지만 메인 스레드 만 UI를 업데이트 할 수 있기 때문에 뷰를 업데이트 할 수 없습니다.
android.view.ViewRoot $ CalledFromWrongThreadException : 견해를 만질 수있는 뷰 계층 구조를 생성 만 원래 스레드
예외 나는 아래의 코드에서 얻을.
[image1.startAnimation (rotation); ' ('applyRotation (0, 90) "메인 쓰레드에서)
package com.example.flip3d;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.ImageView;
public class Flip3d extends Activity {
private ImageView image1;
private ImageView image2;
private boolean isFirstImage = true;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image1 = (ImageView) findViewById(R.id.image01);
image2 = (ImageView) findViewById(R.id.image02);
image2.setVisibility(View.GONE);
image1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (isFirstImage) {
applyRotation(0, 90);
isFirstImage = !isFirstImage;
} else {
applyRotation(0, -90);
isFirstImage = !isFirstImage;
}
}
});
}
private void applyRotation(float start, float end) {
// Find the center of image
final float centerX = image1.getWidth()/2.0f;
final float centerY = image1.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(isFirstImage, image1, image2));
if (isFirstImage)
{
image1.startAnimation(rotation);
} else {
image2.startAnimation(rotation);
}
}
}
] 방법이 UI를 업데이트하고 온 클릭 수신기 내의 회전을 제어 관리 할 수 있을까?
는
잘 질문을 포맷하십시오() runOnUIThread의 UI 코드를 포장하십시오
Oakist, 감사합니다. –