Я создаю простую анимацию в андроиде. Просто переместите изображение ImageView с 1 точки на вторую точку на экране, используя следующий код. img_animation - это ImageView.Анимация Android выглядит отрывистой на устройстве
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/Хореограф: пропущено 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);
}
}
Может кто-нибудь помочь?
Как правило, анимация jerkiness будет отличаться от устройства к устройству. Я думаю, что вы можете помочь в гладкости, гарантируя, что вы делаете одну анимацию за раз, и ваш макет максимально упрощен вокруг представления, в котором происходит анимация. По крайней мере, это помогло мне – ElliotM
В моем макете есть изображение bg и изображение для его перемещения. OnCreate Я только начинаю анимацию. –
на устройстве вы имеете в виду эмулятор или реальное устройство? –