Animation.

Slides:



Advertisements
Similar presentations
Graphics.  2D Graphics using  ImageView  Canvas  ViewAnimation.
Advertisements

User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Basic Animation. Animation 4 options – Animated.gif – Frame by Frame animation – Tweened animation This is our focus – OpenGL ES Graphics API for more.
Android Application Development Tutorial. Topics Lecture 5 Overview Overview of Networking Programming Tutorial 2: Downloading from the Internet.
Android Programming. Outline Preparation Create new project Build and Run a project Debug a project Deploy on devices.
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Lecture Series on Android Programming Lecturer: Prof.Luqun Li Teaching Assistants: Fengyou Sun, Haijun Yang, Ting.
2D Graphics: Part 2.
Chapter 10: Move! Creating Animation
6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin.
Chapter 2: Simplify! The Android User Interface
Flag Quiz App 1 CS7030: Mobile App Development. assets Folder 2 CS7030: Mobile App Development  drawable folder – Image contents at the root level 
@2011 Mihail L. Sichitiu1 Android Introduction GUI Menu Many thanks to Jun Bum Lim for his help with this tutorial.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
Android – Advanced Topics Mobile Application Development Selected Topics – CPIT Oct-15.
User Interfaces: Part 1 (View Groups and Layouts).
Chapter 7: Reveal! Displaying Pictures in a Gallery.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Networking: Part 1 (Web Content). Networking with Android Android provides A full-featured web browser based on Chromium, the open source browser engine.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
Animations 1 Fall 2012 CS2302: Programming Principles.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
Mobile Programming Lecture 11 Animation and TraceView.
Android ImageView and Splash Screen 1. After copying an image file (Ctrl-c or right click copy), right click and paste it into one of the res/drawable.
Android View Stuff. TextViews Display text Display images???
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Basic Animation. Animation 4 options – Animated.gif – Frame by Frame animation – Tweened animation This is our focus – OpenGL ES Graphics API for more.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Mobile Computing Lecture#12 Graphics & Animation.
Events. Slide 2©SoftMoore Consulting Events Events are generated when a user interacts with the view objects of an application. Examples –button clicked–
Flag Quiz Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 10: Move! Creating Animation 1 Android.
CHAPTER 5 Graphics Drawing Audio. Chapter objectives: Learn to draw to a canvas Examine the process of adding drawn elements and UI controls to a layout.
Lecture 3: Animation & Graphics Topics: Animation, Graphics, Drawing Date: Feb 2, 2016.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Chapter 2: Simplify! The Android User Interface
Android Application 2D Graphics cs.
Lecture 3: Animation & Graphics
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
GUI Programming Fundamentals
滑動版面 建國科技大學 資管系 饒瑞佶 2013/7 V1.
CS499 – Mobile Application Development
Lecture 3: Animation & Graphics
Android – Event Handling
Lecture 8: Graphics By: Eliav Menachi.
2D Graphics: Part 2.
S.RENUKADEVI/AP/SCD/ANDROID - Notifications
Android Widgets 1 7 August 2018
ITEC535 – Mobile Programming
Mobile Computing With Android ACST 4550 Android Animation
Picasso Revisted.
Android Programming Lecture 6
CIS 470 Mobile App Development
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
Android Developer Fundamentals V2
滑動 建國科技大學 資管系 饒瑞佶 2013/4 V1 2015/5 V2.
滑動 建國科技大學 資管系 饒瑞佶.
Lecture 3: Animation & Graphics
CIS 470 Mobile App Development
Android SDK & App Development
Lecture 8: Graphics By: Eliav Menachi.
Android Project Structure, App Resources and Event Handling
Adding Components to Activity
CIS 470 Mobile App Development
Android Sensor Programming
Presentation transcript:

Animation

Android Animation Two main types of animations Tween Animation – creates an animation by performing a series of transformations (rotate, scale, etc.) on a single image. Frame Animation – creates an animation by showing a sequence of images in order. Note: Animation can be applied to any View object. ©SoftMoore Consulting

Tween Animation Four types of tween transformations: alpha – translates the transparency of the view from 0.0 (transparent) to 1.0 (opaque) rotate – spins the view clockwise or counterclockwise around a pivot point scale – stretches the view vertically and horizontally from a pivot point translate – moves the view from one position on the screen to another ©SoftMoore Consulting

Defining Tween Animations Tween animations can be defined programmatically in the Java code or declaratively as XML resource files in the /res/anim folder. Java classes (package android.view.animation) AlphaAnimation – RotateAnimation ScaleAnimation – TranslateAnimation XML elements <alpha> – <rotate> <scale> – <translate> It is also possible to define a “set” of transformations to be applied to a view; e.g., rotate and translate. ©SoftMoore Consulting

Example: Tween Animation Copy image android.jpg to folder res/drawable. Create file res/anim/rotate.xml. <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:duration="3000" /> rotate clockwise 360o around the center of the view over a 3-second interval ©SoftMoore Consulting

Example: Tween Animation (continued) Define a view within the layout file for the image. ... <ImageView android:id="@+id/androidImage" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="center" android:src="@drawable/android" /> Note: No file extension. ©SoftMoore Consulting

Example: Tween Animation (continued) Define Java code to start the rotation. Button rotateButton = (Button) findViewById(R.id.rotateButton); rotateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) Animation rotate = AnimationUtils.loadAnimation(MainActivity.this, R.anim.rotate); imageView.startAnimation(rotate); } }); ©SoftMoore Consulting

Example: Tween Animation (continued) ©SoftMoore Consulting

Example: Alpha Animation <?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="3000" /> ©SoftMoore Consulting

Example: Scale Animation <?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:pivotX="50%" android:pivotY="50%" android:fromXScale="0.5" android:fromYScale="0.5" android:toXScale="1.5" android:toYScale="1.5" android:duration="3000" /> ©SoftMoore Consulting

Example: Translate Animation <?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="-200" android:toXDelta="200" android:duration="3000" /> ©SoftMoore Consulting

Example: Pulse Animation <?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:pivotX="50%" android:pivotY="50%" android:fromXScale="0.75" android:fromYScale="0.75" android:toXScale="1.25" android:toYScale="1.25" android:duration="1000" android:repeatCount="4" /> ©SoftMoore Consulting

Example: Tumble Animation <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:duration="3000" /> <translate android:fromXDelta="-200" android:toXDelta="200" </set> Note: Order of animations within the set is important. Changing the order can change the appearance of the animation. ©SoftMoore Consulting

Example: Frame Animation Copy images asteroid01.png, asteroid02.png, …, asteroid12.png to folder res/drawable. Create file res/drawable/astroid_animation.xml. <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/asteroid01" android:duration="200" /> android:drawable="@drawable/asteroid02" ... </animation-list> ©SoftMoore Consulting

Example: Frame Animation (continued) Define a view within the layout file for the image. ... <ImageView android:id="@+id/asteroidImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> ©SoftMoore Consulting

Example: Frame Animation (continued) Define Java code to start the rotation. AnimationDrawable asteroidAnimation; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView asteroidView = (ImageView) findViewById(R.id.asteroidImage); asteroidView.setBackgroundResource (R.drawable.asteroid_animation); asteroidAnimation = (AnimationDrawable) asteroidView.getBackground(); } ©SoftMoore Consulting

Example: Frame Animation (continued) Define Java code to start the rotation (continued). public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) asteroidAnimation.start(); return true; } return super.onTouchEvent(event); ©SoftMoore Consulting

Example: Frame Animation (continued) Imagine the asteroid rotating in place. ©SoftMoore Consulting

Tween Animation on the Asteroid Image In the layout file <ImageView android:id="@+id/asteroidImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center“ android:src="@drawable/asteroid01" /> ©SoftMoore Consulting

Tween Animation on the Asteroid Image (continued) In resource file anim/fall.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <rotate android:fromDegrees="0" android:toDegrees="720" android:pivotX="50%" android:pivotY="50%" android:duration="3000" /> <translate android:interpolator="@android:anim/accelerate_interpolator" android:fromXDelta="-250" android:fromYDelta="-30" android:toXDelta="260" android:toYDelta="700" </set> ©SoftMoore Consulting

Tween Animation on the Asteroid Image (continued) In the Java source code public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) Animation fall = AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.fall); asteroidView.startAnimation(fall); return true; } return super.onTouchEvent(event); ©SoftMoore Consulting

Tween Animation on the Asteroid Image (continued) Imagine the asteroid rotating as it falls from left to right across the screen. ©SoftMoore Consulting

Relevant Links Animation and Graphics Overview Property Animation http://developer.android.com/guide/topics/graphics/overview.html Property Animation http://developer.android.com/guide/topics/graphics/prop-animation.html View Animation http://developer.android.com/guide/topics/graphics/view-animation.html Drawable Animation http://developer.android.com/guide/topics/graphics/drawable-animation.html Animation Resources http://developer.android.com/guide/topics/resources/animation-resource.html ©SoftMoore Consulting