B
B
Byte4K2021-03-26 09:53:05
Java
Byte4K, 2021-03-26 09:53:05

How to make a non-instant transition / reload Activity?

I want the button to glow green after a correct answer and move on to the next question.
But for me it happens instantly and nothing is visible, how to make the transition delay so that the color of the button has time to change, such as a transition after 500ms.

Stopping the thread does not work because everything hangs for Nms, I tested these two methods. and
Thread.sleep(500);

// Handler из android.os.Handler;
Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                /* Code */
            }
        }, 500);


These two methods do not work for me, it just freezes.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dewerro, 2021-03-26
@Byte4K

You can add animation and specify a delay in it, at the same time you will get a beautiful transition. Sorry about Kotlin.
The android:startOffset="500" attribute sets the delay to 500ms.
For example:

button.setOnClickListener {
            val intent = Intent(this, Activity::class.java)
            startActivity(intent)
            overridePendingTransition(R.anim.fade_in, R.anim.fade_out)
        }

fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="300" />

fade_out.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="300"
    android:fromAlpha="1.0"
    android:interpolator="@android:interpolator/accelerate_cubic"
    android:startOffset="100"
    android:toAlpha="0.0"
    android:zAdjustment="top" />

B
Byte4K, 2021-03-27
@Byte4K

In short, Android Studio deleted all java files, now I can't help but restore the fuck.
Let's just say that everything is sorted out.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question