Я создаю простое приложение, которое выглядит как сканер с движущимся фоновым изображением, но оно начинает тормозить, и когда я проверяю профилировщик Android, я замечаю, что оно использует около 400 МБ памяти, и большая часть поступает из графики и родной и я не знаю почему. Может быть, мне нужен какой-нибудь метод recyclerview или destroy в моем коде, чтобы удалить использованную память. Как бы я применил что-то подобное в моем текущем коде?
Изображение моего текущего профиля Android
пакет com.example.android.miulimaapp;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
View white;
Animation downtoup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Remove notification bar
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
//MovingScanSquare
white = findViewById(R.id.white);
downtoup = AnimationUtils.loadAnimation(this, R.anim.downtoup);
white.setVisibility(View.VISIBLE);
downtoup = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.RELATIVE_TO_PARENT, 1.1f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.f);
downtoup.setDuration(2200);
downtoup.setRepeatCount(-1);
downtoup.setRepeatMode(Animation.REVERSE);
downtoup.setInterpolator(new LinearInterpolator());
white.setAnimation(downtoup);
//movingscreen
final ImageView backgroundOne = findViewById(R.id.background_one);
final ImageView backgroundTwo = findViewById(R.id.background_two);
final ValueAnimator animator = ValueAnimator.ofFloat(0.0f, -1.0f);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(2100L);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
final float progress = (float) animation.getAnimatedValue();
final float width = backgroundOne.getWidth();
final float translationX = width * progress;
backgroundOne.setTranslationX(translationX);
backgroundTwo.setTranslationX(translationX + width);
}
});
animator.start();
}
}