Mobile Computing Lecture#12 Graphics & Animation
Lecture Contents Graphics & Animations Drawing Shapes Programmatically Drawing Shapes through XML Frame Animation Bouncing Globe Example Tween Animation Example 2
Drawing a Shape 1. Import the graphics packages 2. Create a View 3. Create a ShapeDrawable to hold our Drawable 4. Create any Shape and assign it to mDrawable 5. The onDraw method is called to draw the graphics 6. Set the boundaries and draw the shape on the canvas 3
Drawing Rectangle 4
Drawing through XML <ScrollView xmlns:android=" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <ImageView android:layout_width="fill_parent" android:layout_height="50dip" /> 5
Drawing through XML 6 <shape xmlns:android=" apk/res/android" type="rectangle"> _______________________ public class Main extends Activity protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.xmlrectangle); }
Multiple Shapes with XML 7
Multiple Shapes 8 SHAPE1 SHAPE5
Multiple Shapes 9 SHAPE2 LINE
Multiple Shapes 10
Frame Animation 11
Main Layout 12
Main.java 13
Main.java …. continue 14
Main.java …. continue 15
Main Points (Frame Animation Example) 1. Bind resources to the ImageView. 2. Call the subclasses MyAnimationRoutine and MyAnimatinoRoutine2 which start and stop the Animation respectively. 3. MyAnimationRoutine extends TimerTask to allow for a wait time before it starts the animation. 4. MyAnimationRoutine2 extends TimerTask to allow for a wait time before it stops the animation from running. 16
Bouncing Globe Example… 17
Bouncing Globe Example … 18
Bouncing Globe Example … 19
Tween Animation Example 20
Tween Animation Example 21
Tween Animation 22
News Feeds Example (News) 23
News Feeds Example (Layout) 24
NewsFeedActivity.java (code…) 25
NewsFeedActivity.java (code…) 26