Android studio | Splash screen with animations using Motion Layout

 

Hi there and welcome to the second splash screen in our website.Please check our previous splash screen :

So in this tutorial we will learn how to create a splash screen using the motion layout.
Source code :
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/motionLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/activity_main_scene"
tools:context=".MainActivity">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/backgroundLayout"
android:layout_width="150dp"
android:layout_height="150dp"
android:background="@drawable/bg"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/blueTwitter"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/twitter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/whiteTwitter"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/twitter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="@color/white" />


</androidx.constraintlayout.motion.widget.MotionLayout>
activity_main_scene.xml :
<?xml version="1.0" encoding="utf-8"?>
<MotionScene
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">

<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@id/start"
motion:duration="1000"
motion:autoTransition="animateToEnd">
<KeyFrameSet>
</KeyFrameSet>
</Transition>

<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@+id/backgroundLayout"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_width="150dp"
android:layout_height="150dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
android:scaleX="10"
android:scaleY="10" />
<Constraint
android:id="@+id/blueTwitter"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_width="100dp"
android:layout_height="100dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
android:scaleX="0"
android:scaleY="0"
android:alpha="0" />
<Constraint
android:id="@+id/whiteTwitter"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_width="100dp"
android:layout_height="100dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
android:scaleX="1"
android:scaleY="1" />
</ConstraintSet>

<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/backgroundLayout"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_width="150dp"
android:layout_height="150dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
android:scaleX="0"
android:scaleY="0" />
<Constraint
android:id="@+id/blueTwitter"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_width="100dp"
android:layout_height="100dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
android:scaleX="1"
android:scaleY="1"
android:alpha="1"
motion:transitionEasing="cubic(1,0,1,0)" />
<Constraint
android:id="@+id/whiteTwitter"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_width="100dp"
android:layout_height="100dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
android:scaleX="0"
android:scaleY="0" />
</ConstraintSet>
</MotionScene>
MainActivity.java :
package m.ify.twitter;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.motion.widget.MotionLayout;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(MainActivity.this,MainActivity2.class));
finish();
}
},3000);


}
}
Watch on youtube :


1 Comments

Previous Post Next Post