Android动画在设备上看起来很不稳定

Android动画在设备上看起来很不稳定,android,animation,native,Android,Animation,Native,我正在android中创建一个简单的动画。只需使用以下代码将一些ImageView从屏幕上的1点移动到第2点即可。 img_动画是ImageView void StartAnimationOne() { m_StartAnimationId = 1; TranslateAnimation animation = new TranslateAnimation(20.0f, 400.0f, 500.0f, 500.0f); animation.

我正在android中创建一个简单的动画。只需使用以下代码将一些ImageView从屏幕上的1点移动到第2点即可。 img_动画是ImageView

void StartAnimationOne()
    {
        m_StartAnimationId = 1;
        TranslateAnimation animation = new TranslateAnimation(20.0f, 400.0f, 500.0f, 500.0f);
        animation.setDuration(m_TotalAnimationTime);
        animation.setRepeatCount(0);
        animation.setRepeatMode(0);
        animation.setFillAfter(true);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //m_StartAnimationId = 2;
                //StartThreadOne();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        Matrix matrix = new Matrix();
        img_animation.setScaleType(ImageView.ScaleType.MATRIX);   //required
        //matrix.postRotate((float) 180f, img_animation.getPivotX(), img_animation.getPivotY());
        matrix.postRotate(0f, img_animation.getDrawable().getBounds().width() / 2,
                img_animation.getDrawable().getBounds().height() / 2);
        img_animation.setImageMatrix(matrix);

        img_animation.startAnimation(animation);
    }
但当它在设备上运行时,动画看起来非常不稳定。 logicat上出现以下警告

I/编舞﹕跳过37帧!应用程序可能在其主线程上做了太多工作。”

我的
main活动是

import android.graphics.Matrix;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class testinglayout extends AppCompatActivity {

    //Skipped 37 frames!  The application may be doing too much work on its main thread.

    ImageView img_animation;

    int m_TotalAnimationTime = 10000;
    int m_StartAnimationId = 1;
    Handler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_testinglayout);

        GetReferences();
        //StartThreadOne();

        //new AnimationClass().execute();

        StartFirst();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_testinglayout, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    void GetReferences()
    {
        img_animation = (ImageView) findViewById(R.id.glowbg);
    }

    void StartFirst()
    {
        runOnUiThread(new Runnable() {
            public void run() {
                //If there are stories, add them to the table
                StartAnimationOne();
            }
        });
    }
    void StartAnimationOne()
    {
        m_StartAnimationId = 1;
        TranslateAnimation animation = new TranslateAnimation(20.0f, 400.0f, 500.0f, 500.0f);
        animation.setDuration(m_TotalAnimationTime);
        animation.setRepeatCount(0);
        animation.setRepeatMode(0);
        animation.setFillAfter(true);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //m_StartAnimationId = 2;
                //StartThreadOne();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        Matrix matrix = new Matrix();
        img_animation.setScaleType(ImageView.ScaleType.MATRIX);   //required
        //matrix.postRotate((float) 180f, img_animation.getPivotX(), img_animation.getPivotY());
        matrix.postRotate(0f, img_animation.getDrawable().getBounds().width() / 2,
                img_animation.getDrawable().getBounds().height() / 2);
        img_animation.setImageMatrix(matrix);

        img_animation.startAnimation(animation);
    }


}

有人能帮忙吗?

试着用
设备
代替android模拟器来调试
并检查应用程序的UI。 如果您认为应用程序在主线程上工作太多,请尝试使用
子线程
来实现一些耗时的功能,这也需要大量资源。
choreographer跳过37帧意味着您的一些动画无法正常工作,请尝试更新AVD,并尝试使用更高版本的android手机进行体验。

通常,动画的抖动会因设备而异。我认为您可以通过确保一次只制作一个动画,并且布局尽可能简单来帮助实现平滑d正在设置动画的视图。至少这是帮助我完成布局的原因。我的布局有一个bg图像和一个要在其上移动的图像。一旦创建,我只是开始动画。在设备上你是指模拟器,还是真实设备?@jordi Castilla-我正在设备(真实)上测试哪种型号、api和多少可用内存(ram和内部)?我使用的是摩托罗拉E。它的动画不是很大。将图像从一个点移动到另一个点。