Animation on Android Locking

Asked

Viewed 66 times

0

I’m making an animation in Android Studio for an app, but when running it runs with a few crashes as if it were losing frames. Does anyone know what it can be?

package com.example.lucas.tostudy;

import android.content.Intent;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.graphics.PixelFormat;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class SplashScreen extends AppCompatActivity {

    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        Window window = getWindow();
        window.setFormat(PixelFormat.RGBA_8888);
    }

    Thread splashTread;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);

        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
        StartAnimations();
    }


    private void StartAnimations() {
        Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
        anim.reset();
        ConstraintLayout c=(ConstraintLayout) findViewById(R.id.cons_layout);
        c.clearAnimation();
        c.startAnimation(anim);

        anim = AnimationUtils.loadAnimation(this, R.anim.translate);
        anim.reset();
        ImageView iv = (ImageView) findViewById(R.id.imgLogo);
        iv.clearAnimation();
        iv.startAnimation(anim);

        anim = AnimationUtils.loadAnimation(this, R.anim.translate);
        anim.reset();
        ImageView iv2 = (ImageView) findViewById(R.id.imgLogoEscrito);
        iv2.clearAnimation();
        iv2.startAnimation(anim);

        splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    // Splash screen pause time
                    while (waited < 5000) {
                        sleep(100);
                        waited += 100;
                    }
                    Intent intent = new Intent(SplashScreen.this,
                            MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    startActivity(intent);
                    SplashScreen.this.finish();
                } catch (InterruptedException e) {
                    // do nothing
                } finally {
                    SplashScreen.this.finish();
                }

            }
        };
        splashTread.start();

    }

}
  • I had a similar problem, that the thread gave a "lag", I replaced it with this code, and it helped in my case, could you test it? private Runnable t1 = new Runnable() {&#xA; @Override&#xA; public void run() {&#xA; try {&#xA; // Coloque aqui seu codigo.&#xA; } catch (Exception e){&#xA; e.printStackTrace();&#xA; }&#xA; }&#xA; }; And then on onCreate to call the thread this: new Thread(t1).start();

  • The problem persisted.

  • I solved the problem using the tips of this post https://stackoverflow.com/questions/12726660/android-animation-reduce-stutter-choppy-lag

  • I solved the problem using the tips of this post https://stackoverflow.com/questions/12726660/android-animation-reduce-stutter-choppy-lag

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.