Android:OutOfMemory错误setContextView

时间:2016-04-03 01:40:50

标签: android android-studio

我正在尝试简单的动画,但MainActivity中的setContextView(下面代码中的第16行)抛出了OutOfMemory错误。我尝试删除我的onCreate()方法代码,看看它是否发生没有它,但仍然发生错误。

arg1, arg2 = 5, 6

XML:

 package com.example.ryan.firstanimation;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    animator = new ObjectAnimator();
    animator.addListener(listener);
    arrowView = (ImageView) findViewById(R.id.upArrow);
    animator.setTarget(arrowView);
    firstLeft = arrowView.getLeft();
    button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            animator.start();

        }
    });

}

ImageView arrowView;
int firstLeft;

int left;
int right;
int top;
int bottom;
Button button;

Animator animator;
Animator.AnimatorListener listener = new Animator.AnimatorListener() {
    @Override
    public void onAnimationStart(Animator animation) {
        left=arrowView.getLeft();
        right=arrowView.getRight();
        top = arrowView.getTop();
        bottom = arrowView.getBottom();

    }

    @Override
    public void onAnimationEnd(Animator animation) {

    }

    @Override
    public void onAnimationCancel(Animator animation) {
        animator.cancel();
    }

    @Override
    public void onAnimationRepeat(Animator animation) {
        if (arrowView.getRight() < 360) {
            left++;
            arrowView.setLeft(left);
        } else{
            arrowView.setLeft(firstLeft);
        }
    }
};
}

0 个答案:

没有答案