SlideShare a Scribd company logo
Android Animation
Topics
• Frame by Frame animation
• Tween animation
> Translate, Rotate, Scale, Alpha
• Interpolator
• Layout animation
Frame-by-Frame Animationnim
What is Frame-by-Frame Animation?
• Created with a sequence of different images,
played in order, like a roll of film.
• Pieces
> The frames in the /res/drawable directory
> Animation resource XML file in which the frames
are specified as <item> under <animation-list>
> Code that loads the Animation resource XML file
Animation XML Resource
• The XML file consists of an <animation-list>
element as the root node and a series of child
<item> nodes that each define a frame
<?xml version="1.0" encoding="UTF-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
id="selected" android:oneshot="false">
<item android:drawable="@drawable/ball1" android:duration="50" />
<item android:drawable="@drawable/ball2" android:duration="50" />
<item android:drawable="@drawable/ball3" android:duration="50" />
<item android:drawable="@drawable/ball4" android:duration="50" />
<item android:drawable="@drawable/ball5" android:duration="50" />
<item android:drawable="@drawable/ball6" android:duration="50" />
</animation-list>
Code That Starts the Animation
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.framebyframe);
// Load the ImageView that will host the animation and
// set its background to the AnimationDrawable XML resource.
ImageView img = (ImageView) findViewById(R.id.my_image_view);
img.setBackgroundResource(R.anim.simple_animation);
// Get the background, which has been compiled to an AnimationDrawable object.
frameAnimation = (AnimationDrawable) img.getBackground();
}
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (animationStarted){
frameAnimation.stop();
animationStarted = false;
}
else{
frameAnimation.start();
animationStarted = true;
}
return true;
}
return super.onTouchEvent(event);
Tween Animationnimation
Built-in Tween Animation Schemes
• TransitionAnimation
> Position change
• RotateAnimation
> Rotation
• ScaleAnimation
> Scaling
• AlphaAnimation
> Transparancy
Steps of Tween Animation
• Create XML animation resource file in
/res/anim/ directory
• Load the XML animation resource file into
Animation object
• Start the animation
Create Animation XML Resource
• The XML file is located under /res/anim/ directory
• Example below is for Rotate animation
<?xml version="1.0" encoding="UTF-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="270"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="700"
android:duration="700" />
Create Animation XML Resource
• Sequential animation is done with <set>
• Example below - Translate animation followed by
Rotate animation
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0"
android:toXDelta="100"
android:fromYDelta="0"
android:toYDelta="150"
android:duration="1000" />
<rotate
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="270"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="700"
android:duration="700" />
</set>
Loading Animation Resource &
Staring Animation
// Load Animation object from a resource
Animation rotate = AnimationUtils.loadAnimation(this,
R.anim.rotate);
// Select the animation target and start the animation
findViewById(R.id.myimage).startAnimation(rotate);
Interpolatornterpolator
What is Interpolator
• An interpolator defines the rate of change of an
animation.
• This allows the basic animation effects (alpha,
scale, translate, rotate) to be accelerated,
decelerated, repeated, etc.
• You can set an interpolator either in XML
animation resource file or programmatically
Built-in Android Interpolators
• Built-in Android Interpolators
> android.R.anim.accelerate_interpolator
> android.R.anim.decelerate_interpolator
> android.R.anim.accelerate_decelerate_interpolator
> android.R.anim.anticipate_interpolator
> android.R.anim.overshoot_interpolator
• Example of setting interpolator programmatically
mAnimation.setInterpolator( AnimationUtils.loadInterpolator(this,
android.R.anim.accelerate_interpolator));
Layout Animationnimatio
What is Layout Animation?
• Animations are applied when components are
laid out
> When components are added or removed from
layouts, these animations are triggered.
Steps for Layout Animation
1.Create “layout animation” resource files
under /res/anim/ directory
2.Add android:layoutAnimation=@anim/<layout-
animation-resource-file> attribute to the layout
3.Load the layout resource file as you normally
do
1. Create Animation XML Resources
• Create it under /res/anim/ directory - let's call it
/res/anim/layout_bottom_to_top_slide.xml
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation
xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="500%"
android:animationOrder="reverse"
android:animation="@anim/slide_right" />
• The above uses /res/anim/slide_right.xml below
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="-100%p" android:toXDelta="0"
android:duration="@android:integer/config_shortAnimTime" />
</set>
2. Create Layout Resource File
• Layout resource file now has
android:layoutAnimation attribute
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutAnimation="@anim/layout_bottom_to_top_slide" />
3. Load Layout resource
• There is nothing different in this code
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_animation_3);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, mStrings));
}
23
Thank you
hank you!

More Related Content

PPTX
Broadcast Receiver
PPTX
Flask – Python
PPT
RichControl in Asp.net
PDF
Android notification
PPTX
Event handling
PPTX
Notification android
PPTX
Java swing
PPTX
Android UI
Broadcast Receiver
Flask – Python
RichControl in Asp.net
Android notification
Event handling
Notification android
Java swing
Android UI

What's hot (20)

PPSX
JDBC: java DataBase connectivity
PPTX
JAVA AWT
PPTX
jQuery
PPT
android menus
PPTX
Network programming in java - PPT
PPTX
Content provider in_android
PDF
Android Networking
PPT
JQuery introduction
PPTX
Computer animation Computer Graphics
PPT
Jsp/Servlet
PPTX
SQLite database in android
PPT
DOM and SAX
PPT
android content providers
PPTX
PPTX
graphics programming in java
PDF
Servlet and servlet life cycle
PDF
Android graphics
PPTX
Introduction to Node.js
JDBC: java DataBase connectivity
JAVA AWT
jQuery
android menus
Network programming in java - PPT
Content provider in_android
Android Networking
JQuery introduction
Computer animation Computer Graphics
Jsp/Servlet
SQLite database in android
DOM and SAX
android content providers
graphics programming in java
Servlet and servlet life cycle
Android graphics
Introduction to Node.js
Ad

Viewers also liked (20)

PPTX
Android animation theory
PDF
Introduction to Android Animations
PPTX
Android Training (Animation)
PPTX
Basic Android Animation
PPTX
Android Transition
ODP
Android App Development - 12 animations
PDF
[Android] Android Animation
PPTX
ppt based on android technology with great animations
PDF
Android design and Custom views
PPTX
Android Animator
PPTX
Material design for android
PPTX
School Management System in Android
PDF
Android Material Design APIs/Tips
PPTX
Material design - AndroidosDay 2015
POT
Android Material Design
PDF
Material design basics
PPTX
Materials design
PPTX
Esp chap 4 materials design (finished)
PPTX
Material Design Android
PDF
Android tutorial ppt
Android animation theory
Introduction to Android Animations
Android Training (Animation)
Basic Android Animation
Android Transition
Android App Development - 12 animations
[Android] Android Animation
ppt based on android technology with great animations
Android design and Custom views
Android Animator
Material design for android
School Management System in Android
Android Material Design APIs/Tips
Material design - AndroidosDay 2015
Android Material Design
Material design basics
Materials design
Esp chap 4 materials design (finished)
Material Design Android
Android tutorial ppt
Ad

Similar to Android animation (20)

DOCX
Android view animation in android-chapter18
DOCX
Android animation and color state list resources-chapter 10
PPTX
Android animations
PPTX
Animation in android
PPTX
Animate me, If you don't do it for me do it for Chet :)
PPTX
Animation
PPTX
Animate Me! if you don't do it for me, do it for Chet - DroidconLondon2015
PPTX
Animate Me, if you don't do it for me do it for chet (DroidCon Paris)
PPTX
Have fun with animation
PDF
Android RotateAnimation 簡介
PDF
Animações Fluídas no Android - DevFestPR 17
DOCX
Android animation in android-chapter17
PDF
Demystifying Angular Animations
PPTX
Android webinar class_4
KEY
Animation in iOS
PDF
The world of Android Animations
ODP
Day seven
PDF
Beauty Treatment for your Android Application
PDF
How to implement react native animations using animated api
PDF
How to Create Custom Animations in Flutter – A Step-by-Step Guide.pdf
Android view animation in android-chapter18
Android animation and color state list resources-chapter 10
Android animations
Animation in android
Animate me, If you don't do it for me do it for Chet :)
Animation
Animate Me! if you don't do it for me, do it for Chet - DroidconLondon2015
Animate Me, if you don't do it for me do it for chet (DroidCon Paris)
Have fun with animation
Android RotateAnimation 簡介
Animações Fluídas no Android - DevFestPR 17
Android animation in android-chapter17
Demystifying Angular Animations
Android webinar class_4
Animation in iOS
The world of Android Animations
Day seven
Beauty Treatment for your Android Application
How to implement react native animations using animated api
How to Create Custom Animations in Flutter – A Step-by-Step Guide.pdf

More from Krazy Koder (20)

PPT
2310 b xd
PPT
2310 b xd
PPT
2310 b xd
PPT
2310 b xc
PPT
2310 b xb
PPT
2310 b 17
PPT
2310 b 16
PPT
2310 b 16
PPT
2310 b 15
PPT
2310 b 15
PPT
2310 b 14
PPT
2310 b 13
PPT
2310 b 12
PPT
2310 b 11
PPT
2310 b 10
PPT
2310 b 09
PPT
2310 b 08
PPT
2310 b 08
PPT
2310 b 08
PPT
2310 b 07
2310 b xd
2310 b xd
2310 b xd
2310 b xc
2310 b xb
2310 b 17
2310 b 16
2310 b 16
2310 b 15
2310 b 15
2310 b 14
2310 b 13
2310 b 12
2310 b 11
2310 b 10
2310 b 09
2310 b 08
2310 b 08
2310 b 08
2310 b 07

Recently uploaded (20)

PPTX
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
PDF
How to Get Business Funding for Small Business Fast
PDF
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
DOCX
unit 1 COST ACCOUNTING AND COST SHEET
DOCX
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
PDF
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
DOCX
Business Management - unit 1 and 2
PDF
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
PDF
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
PDF
Unit 1 Cost Accounting - Cost sheet
PDF
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
PPTX
AI-assistance in Knowledge Collection and Curation supporting Safe and Sustai...
PPTX
5 Stages of group development guide.pptx
PDF
Reconciliation AND MEMORANDUM RECONCILATION
PPTX
Belch_12e_PPT_Ch18_Accessible_university.pptx
PPTX
Amazon (Business Studies) management studies
PPTX
HR Introduction Slide (1).pptx on hr intro
PPTX
New Microsoft PowerPoint Presentation - Copy.pptx
PPTX
Principles of Marketing, Industrial, Consumers,
PDF
Chapter 5_Foreign Exchange Market in .pdf
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
How to Get Business Funding for Small Business Fast
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
unit 1 COST ACCOUNTING AND COST SHEET
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
Business Management - unit 1 and 2
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
Unit 1 Cost Accounting - Cost sheet
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
AI-assistance in Knowledge Collection and Curation supporting Safe and Sustai...
5 Stages of group development guide.pptx
Reconciliation AND MEMORANDUM RECONCILATION
Belch_12e_PPT_Ch18_Accessible_university.pptx
Amazon (Business Studies) management studies
HR Introduction Slide (1).pptx on hr intro
New Microsoft PowerPoint Presentation - Copy.pptx
Principles of Marketing, Industrial, Consumers,
Chapter 5_Foreign Exchange Market in .pdf

Android animation

  • 2. Topics • Frame by Frame animation • Tween animation > Translate, Rotate, Scale, Alpha • Interpolator • Layout animation
  • 4. What is Frame-by-Frame Animation? • Created with a sequence of different images, played in order, like a roll of film. • Pieces > The frames in the /res/drawable directory > Animation resource XML file in which the frames are specified as <item> under <animation-list> > Code that loads the Animation resource XML file
  • 5. Animation XML Resource • The XML file consists of an <animation-list> element as the root node and a series of child <item> nodes that each define a frame <?xml version="1.0" encoding="UTF-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" id="selected" android:oneshot="false"> <item android:drawable="@drawable/ball1" android:duration="50" /> <item android:drawable="@drawable/ball2" android:duration="50" /> <item android:drawable="@drawable/ball3" android:duration="50" /> <item android:drawable="@drawable/ball4" android:duration="50" /> <item android:drawable="@drawable/ball5" android:duration="50" /> <item android:drawable="@drawable/ball6" android:duration="50" /> </animation-list>
  • 6. Code That Starts the Animation public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.framebyframe); // Load the ImageView that will host the animation and // set its background to the AnimationDrawable XML resource. ImageView img = (ImageView) findViewById(R.id.my_image_view); img.setBackgroundResource(R.anim.simple_animation); // Get the background, which has been compiled to an AnimationDrawable object. frameAnimation = (AnimationDrawable) img.getBackground(); } public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (animationStarted){ frameAnimation.stop(); animationStarted = false; } else{ frameAnimation.start(); animationStarted = true; } return true; } return super.onTouchEvent(event);
  • 8. Built-in Tween Animation Schemes • TransitionAnimation > Position change • RotateAnimation > Rotation • ScaleAnimation > Scaling • AlphaAnimation > Transparancy
  • 9. Steps of Tween Animation • Create XML animation resource file in /res/anim/ directory • Load the XML animation resource file into Animation object • Start the animation
  • 10. Create Animation XML Resource • The XML file is located under /res/anim/ directory • Example below is for Rotate animation <?xml version="1.0" encoding="UTF-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromDegrees="0" android:toDegrees="270" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="700" />
  • 11. Create Animation XML Resource • Sequential animation is done with <set> • Example below - Translate animation followed by Rotate animation <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <translate android:fromXDelta="0" android:toXDelta="100" android:fromYDelta="0" android:toYDelta="150" android:duration="1000" /> <rotate android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromDegrees="0" android:toDegrees="270" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="700" /> </set>
  • 12. Loading Animation Resource & Staring Animation // Load Animation object from a resource Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate); // Select the animation target and start the animation findViewById(R.id.myimage).startAnimation(rotate);
  • 14. What is Interpolator • An interpolator defines the rate of change of an animation. • This allows the basic animation effects (alpha, scale, translate, rotate) to be accelerated, decelerated, repeated, etc. • You can set an interpolator either in XML animation resource file or programmatically
  • 15. Built-in Android Interpolators • Built-in Android Interpolators > android.R.anim.accelerate_interpolator > android.R.anim.decelerate_interpolator > android.R.anim.accelerate_decelerate_interpolator > android.R.anim.anticipate_interpolator > android.R.anim.overshoot_interpolator • Example of setting interpolator programmatically mAnimation.setInterpolator( AnimationUtils.loadInterpolator(this, android.R.anim.accelerate_interpolator));
  • 17. What is Layout Animation? • Animations are applied when components are laid out > When components are added or removed from layouts, these animations are triggered.
  • 18. Steps for Layout Animation 1.Create “layout animation” resource files under /res/anim/ directory 2.Add android:layoutAnimation=@anim/<layout- animation-resource-file> attribute to the layout 3.Load the layout resource file as you normally do
  • 19. 1. Create Animation XML Resources • Create it under /res/anim/ directory - let's call it /res/anim/layout_bottom_to_top_slide.xml <?xml version="1.0" encoding="utf-8"?> <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="500%" android:animationOrder="reverse" android:animation="@anim/slide_right" /> • The above uses /res/anim/slide_right.xml below <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator"> <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="@android:integer/config_shortAnimTime" /> </set>
  • 20. 2. Create Layout Resource File • Layout resource file now has android:layoutAnimation attribute <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" android:layoutAnimation="@anim/layout_bottom_to_top_slide" />
  • 21. 3. Load Layout resource • There is nothing different in this code public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_animation_3); setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings)); }