Arun pujari
Arun pujari

Reputation: 39

Animating two ImageViews in android

I have two linear layouts inside the main linear layout, and I set the two linear layouts background images. Now I want to display both images one by one. The first image should be displayed with fade in animation slowly; after completion of this, the second image should also be displayed slowly with fade in animation. How can I do that? My code and the screenshot are given below. Thanks in advance.

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_weight="15"
        android:id="@+id/L1"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@drawable/b2">
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#ffffffff" />

    <LinearLayout
        android:layout_weight="85"
        android:id="@+id/L2"
        android:orientation="vertical"`
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@drawable/b1">
    </LinearLayout>

</LinearLayout>

Upvotes: 1

Views: 245

Answers (1)

Capricorn
Capricorn

Reputation: 2089

Programmatical solution (in Java):

ObjectAnimator animPic1 = ObjectAnimator.ofFloat(viewL1, "alpha", 0f, 1f);
ObjectAnimator animPic2 = ObjectAnimator.ofFloat(viewL2, "alpha", 0f, 1f);
AnimatorSet animSet = new AnimatorSet();
animSet.playSequentially(animPic1, animPic2);
animSet.start();

An alternative is to define the animation in XML resource files, load them and apply them to the desired view objects. A good introduction into these basic animation in android may be found at http://blog.stylingandroid.com/simple-animation-part-1/

Upvotes: 1

Related Questions