Animated Gradient Background in Android

Animated Gradient Background in Android - Hello friend inabnomaniiyaha, In the article that you read this time with the title Animated Gradient Background in Android, we have prepared this article well for you to read and take information in it. hopefully the contents of the post Artikel android-example,what we write you can understand. Alright, happy reading.

Judul : Animated Gradient Background in Android
link : Animated Gradient Background in Android

Baca juga


Animated Gradient Background in Android

Android Gradient Drawables

Now we will create different gradient drawables with different color and file name. Here we create gradient_1.xml, gradient_2.xml and gradient_3.xml XML drawable files with gradient attributes android:angle, android:endColor and android:startColor. Following is the XML code of three drawable files.

res/drawable/gradient_1.xml

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <gradient

        android:angle="225"

        android:endColor="#044fab"

        android:startColor="#21d6d3" />

</shape>

res/drawable/gradient_2.xml

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <gradient

        android:angle="45"

        android:endColor="#933c94"

        android:startColor="#517f95" />

</shape>

res/drawable/gradient_3.xml

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <gradient

        android:angle="135"

        android:endColor="#43b4ef"

        android:startColor="#d40845" />

</shape>

Now create a new XML drawable file android_gradient_list.xml and add the following code which contains the AnimationList, which is responsible to change the background color from one gradient to another. In the AnimationList tag, add 3 items and referring to the above 3 XML drawable files.

res/drawable/android_gradient_list.xml

<animation-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item

        android:drawable="@drawable/gradient_1"

        android:duration="4000" />


    <item

        android:drawable="@drawable/gradient_2"

        android:duration="4000" />


    <item

        android:drawable="@drawable/gradient_3"

        android:duration="4000" />

</animation-list>

XML Layout File

Open your app main XML layout file activity_main.xml and set background to the root layout (View or ViewGroup) of the activity where you want to add animated gradient background. Also give an id to that layout; we will need to refer in java activity file.

Animated Gradient Background in Android

res/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"

    android:layout_height="match_parent"

    android:id="@+id/root_layout"

    android:background="@drawable/android_gradient_list"

    tools:context="com.viralandroid.animatedgradientandroid.MainActivity">


    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:gravity="center"

        android:text="Android \nBackground \nAnimated Gradient"

        android:textColor="#ffffff"

        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintLeft_toLeftOf="parent"

        app:layout_constraintRight_toRightOf="parent"

        app:layout_constraintTop_toTopOf="parent" />


</android.support.constraint.ConstraintLayout>



That's the articleAnimated Gradient Background in Android

That's it for the article Animated Gradient Background in Android this time, hopefully can be useful for all of you. well, see you in another article post.

You are now reading the articleAnimated Gradient Background in Android with link addresshttps://inabnonapudyawanabing.blogspot.com/2020/12/animated-gradient-background-in-android.html

0 Response to "Animated Gradient Background in Android"

Post a Comment

Tips Tricks for Android Phone

Tips & Tricks for Android Phone is a free android app and Collection of Tips and Tricks related to using your android mobile device lik...