WMS Exp10
WMS Exp10
Experiment No: 10
Aim: Create animations and graphical primitives in Android environment
Introduction: Android graphics provides low level graphics tools such as canvases, color,
filters, points and rectangles which handle drawing to the screen directly.
● Android provides a huge set of 2D-drawing APIs that allow you to create graphics.
● Android has got visually appealing graphics and mind blowing animations.
● The Android framework provides a rich set of powerful APIS for applying animation to UI
elements and graphics as well as drawing custom 2D and 3D graphics.
Following are the three animation systems used in Android applications:
1. Property Animation
2. View Animation
3. Drawable Animation
Property Animation
● Property animation is the preferred method of animation in Android.
● This animation is the robust framework which lets you animate any properties of any
objects, view or non-view objects.
● The android.animation provides classes which handle property animation.
2. View Animation
● View Animation is also called as Tween Animation.
● The android.view.animation provides classes which handle view animation.
● This animation can be used o animate the content of a view.
t
● It is limited to simple transformation such as moving, re-sizing and rotation, but not its
background color.
3. Drawable Animation
● Drawable animation is implemented using the AnimationDrawable class.
● This animation works by playing a running sequence of 'Drawable' ources that is
dis res
images, frame by frame inside a view object.
The android.graphics.Paint class is used with canvas to draw objects. It holds the information
of color and style.
Canvas
● Android graphics provides low level graphics tools such as canvases, color, filters, points
and rectangles which handle drawing to the screen directly.
● The Android framework provides a set of 2D-DRAWING APIs which allows user to
provide own custom graphics onto a canvas or to modify existing views to customize their
look and feel.
Steps/Method/Coding:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageview"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:contentDescription="@string/app_name"
android:src="@drawable/gfgimage" />
<LinearLayout
android:id="@+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/imageview"
android:layout_marginTop="30dp"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="@+id/BTNblink"
style="@style/TextAppearance.AppCompat.Widget.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/blink"
android:textColor="@color/white" />
<Button
android:id="@+id/BTNrotate"
style="@style/TextAppearance.AppCompat.Widget.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/clockwise"
android:textColor="@color/white" />
<!--To start the fading animation of the image-->
<Button
android:id="@+id/BTNfade"
style="@style/TextAppearance.AppCompat.Widget.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/fade"
android:textColor="@color/white" />
</LinearLayout>
<LinearLayout
android:id="@+id/linear2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linear1"
android:layout_marginTop="30dp"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="@+id/BTNmove"
style="@style/TextAppearance.AppCompat.Widget.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/move"
android:textColor="@color/white" />
<Button
android:id="@+id/BTNslide"
style="@style/TextAppearance.AppCompat.Widget.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/slide"
android:textColor="@color/white" />
<Button
android:id="@+id/BTNzoom"
style="@style/TextAppearance.AppCompat.Widget.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/zoom"
android:textColor="@color/white" />
</LinearLayout>
<Button
android:id="@+id/BTNstop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linear2"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:layout_marginRight="30dp"
android:text="@string/stop_animation" />
</RelativeLayout>
Output screenshot:
Learning Outcomes: Learned Basics of Android, Android Layouts and Widgets and
Communication and Media.