ImageViewをアニメーション化するオブジェクトアニメーターを追加する前は、正常に実行されていました。しかし、アニメーションを作成した後、ランタイム例外をスローし始めました。アニメーターが原因であることがわかっているのに、何が問題なのか理解できません。アニメーターの初期化のコードを削除すると、問題なく動作するからです。誰かが私がこれを解決するのを手伝ってください。ありがとう!これは、ランタイム例外のスタックです。
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2304
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2354
ActivityThread.access$600(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 150
ActivityThread$H.handleMessage(Message) line: 1244
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 137
ActivityThread.main(String[]) line: 5191
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 511
ZygoteInit$MethodAndArgsCaller.run() line: 795
ZygoteInit.main(String[]) line: 562
NativeStart.main(String[]) line: not available [native method]
これは私のコードです:
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
public class Startup extends Activity {
private boolean itIsMultiplayerCard = false;
private float x, y;
private int screenWidth, screenHeight, initX, finX;
private Animation goDown, goUp;
private ObjectAnimator centerSlider;
private DisplayMetrics displayMetrics;
private FrameLayout startUpFrameLayout;
private ImageView backImageView, playNowImageView, multiplayerImageView, optionsImageView, exitImageView;
private OnClickListener backImageListener = new OnClickListener() {
@Override
public void onClick(View v) {
}
};
private OnClickListener playNowListener = new OnClickListener() {
@Override
public void onClick(View v) {
}
};
private OnClickListener multiplayerListener = new OnClickListener() {
@Override
public void onClick(View v) {
itIsMultiplayerCard = true;
optionsImageView.setOnClickListener(null);
exitImageView.setOnClickListener(null);
multiplayerImageView.setOnClickListener(backListener);
multiplayerImageView.startAnimation(goDown);
multiplayerImageView.setImageResource(R.drawable.blank);
multiplayerImageView.bringToFront();
multiplayerImageView.startAnimation(goUp);
}
};
private OnClickListener optionsListener = new OnClickListener() {
@Override
public void onClick(View v) {
itIsMultiplayerCard = false;
multiplayerImageView.setOnClickListener(null);
exitImageView.setOnClickListener(null);
optionsImageView.setOnClickListener(backListener);
optionsImageView.startAnimation(goDown);
optionsImageView.setImageResource(R.drawable.blank);
optionsImageView.bringToFront();
optionsImageView.startAnimation(goUp);
}
};
private OnClickListener exitListener = new OnClickListener() {
@Override
public void onClick(View v) {
System.exit(0);
}
};
private OnClickListener backListener = new OnClickListener() {
@Override
public void onClick(View v) {
if(itIsMultiplayerCard) {
optionsImageView.setOnClickListener(optionsListener);
multiplayerImageView.setOnClickListener(multiplayerListener);
multiplayerImageView.startAnimation(goDown);
multiplayerImageView.setImageResource(R.drawable.mul_u);
playNowImageView.bringToFront();
backImageView.bringToFront();
multiplayerImageView.startAnimation(goUp);
} else {
multiplayerImageView.setOnClickListener(multiplayerListener);
optionsImageView.setOnClickListener(optionsListener);
optionsImageView.startAnimation(goDown);
optionsImageView.setImageResource(R.drawable.op_u);
multiplayerImageView.bringToFront();
playNowImageView.bringToFront();
backImageView.bringToFront();
optionsImageView.startAnimation(goUp);
}
itIsMultiplayerCard = false;
exitImageView.setOnClickListener(exitListener);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_startup);
displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
screenHeight = displayMetrics.heightPixels;
screenWidth = displayMetrics.widthPixels;
initX = backImageView.getWidth();
finX = ((screenWidth / 2) - (235 / 2));
goUp = AnimationUtils.loadAnimation(this, R.anim.go_up);
goDown = AnimationUtils.loadAnimation(this, R.anim.go_down);
startUpFrameLayout = (FrameLayout) findViewById(R.id.startUpFrameLayout);
backImageView = (ImageView) findViewById(R.id.backImageView);
playNowImageView = (ImageView) findViewById(R.id.playNowImageView);
multiplayerImageView = (ImageView) findViewById(R.id.multiplayerImageView);
optionsImageView = (ImageView) findViewById(R.id.optionsImageView);
exitImageView = (ImageView) findViewById(R.id.exitImageView);
centerSlider = ObjectAnimator.ofFloat(backImageView, "TranslationX", -117, 117);
backImageView.setOnClickListener(backImageListener);
playNowImageView.setOnClickListener(playNowListener);
multiplayerImageView.setOnClickListener(multiplayerListener);
optionsImageView.setOnClickListener(optionsListener);
exitImageView.setOnClickListener(exitListener);
playNowImageView.setAlpha(0.0f);
multiplayerImageView.setAlpha(0.0f);
optionsImageView.setAlpha(0.0f);
exitImageView.setAlpha(0.0f);
centerSlider.setDuration(300);
centerSlider.start();
}
}