Android Ex 09
Android Ex 09
<ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/flowers1" />
<ImageView
android:id="@+id/img2"
android:layout_width="match_parent"
android:layout_height="218dp"
app:srcCompat="@drawable/bird" />
<ImageView
android:id="@+id/img3"
android:layout_width="match_parent"
android:layout_height="218dp"
android:layout_below="@+id/imageButton2"
android:layout_marginTop="263dp"
app:srcCompat="@drawable/butterfly" />
</RelativeLayout>
Step 3: Create a new folder ‘anim’ of type ‘anim’ inside the ‘/res’ directory.
Step 4: Create new animation resource file fade.xml inside the created ‘/anim’
directory.
fade.xml
Step 5: Create new animation resource file blink.xml inside the created ‘/anim’
directory.
blink.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0" android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="600"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
</set>
Step 6: Create new animation resource file slide.xml inside the created ‘/anim’
directory.
Slide.xml
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/linear_interpolator"
android:toXScale="1.0"
android:toYScale="0.0" />
</set>
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image1 = (ImageView) findViewById(R.id.img1);
image2 = (ImageView) findViewById(R.id.img2);
image3 = (ImageView) findViewById(R.id.img3);
Animation anim1 =
AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade);
image2.startAnimation(anim1);
Animation anim2 =
AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide);
image1.startAnimation(anim2);
Animation anim3 =
AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
image3.startAnimation(anim3);
}
}