我在android中创建一个简单的动画。只需要使用以下代码将一些ImageView从1点移动到屏幕上的第2点。 img_animation是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);
}
但是当它在设备上运行时,动画看起来非常生涩。 跟随警告发出警告。
I / Choreographer:跳过37帧!应用程序可能在其主线程上做了太多工作。“
我的MainActivity
是
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);
}
}
有人可以帮忙吗?
答案 0 :(得分:0)
尝试使用.footer
代替android模拟器到device
并检查应用程序的UI。
如果您认为应用程序在主线程上工作太多,请尝试使用debug
长时间使用功能,这也需要大量资源。
和编舞者跳过37帧意味着你的一些动画无法正常工作尝试更新AVD并尝试更高级的Android手机品尝。