SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Android Bootcamp
SESSION 9 – TOUCH EVENTS
Agenda
 Event Handlers & Event Listeners
 Building Menus
 Fling Gestures
 Multi Touch events
 Animation
 Styles
2
Event Handlers and Event Listeners
 Most user interaction with an Android device is captured
by the system and sent to a corresponding callback
method.
 These events can be handled by extending the class
and overriding the methods, called event handlers.
 User interaction with View or ViewGroup objects can
also support event listeners.
 For example, the setOnClickListener() event listener can
be registered for a button and when it is pressed, the
onClick() method is called.
3
Intercepting a Physical Key Press 4
Source: Android Cookbook Text Book (Refer Handout)
Intercepting a Physical Key Press
 The system first sends any KeyEvent to the appropriate callback method
in the in-focus activity or view.
 These callback methods are :
 onKeyUp(), onKeyDown(), onKeyLongPress()—Physical key press
callbacks.
 onTrackballEvent(), onTouchEvent()—Trackball and touchscreen press
callbacks
 onFocusChanged()—Called when the view gains or loses focus
 These can be overridden by the application to customize with different
actions.
 For example, to turn off the camera button (to avoid accidental
presses), just consume the event in the onKeyDown() callback method
for the Activity.
5
Intercepting a Physical Key Press
 This is done by intercepting the method for the event
KeyEvent.KEYCODE_CAMERA and returning true:
 public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_CAMERA) {
return true; // consume event, hence do nothing on camera button
}
return super.onKeyDown(keyCode, event);
}
 By consuming the event, it does not get passed on to other Android
components.
 There are a few exceptions to this:
 The Power button and HOME key are intercepted by the system and do not reach the application for
customization.
 The BACK, MENU, HOME, and SEARCH keys should not intercept the KeyDown but instead the KeyUp.
6
Building Menus
 A developer can implement three types of menus in Android
 Options menu—The main menu for an Activity that displays when the
MENU key is pressed.
 Context Menu—A floating list of menu items that displays when a view is
long pressed.
 Submenu—A floating list of menu items that displays when a menu item
is pressed.
 The Options menu is created the first time the MENU key is pressed in an
activity.
 This launches the onCreateOptionsMenu() method that usually contains
Menu methods, such as:
 menu.add(GROUP_DEFAULT, MENU_ADD, 0, "Add")
.setIcon(R.drawable.icon);
7
Building Menus
 the onPrepareOptionsMenu() can be used if any of the menu options
need to change during run-time
 When an item from the options menu is clicked, the
onOptionsItemSelected() method is called.
 This passes the selected item ID, and a switch statement can be used to
determine which option was selected.
Utilizing Search KEY
 If an activity in the in-focus application is defined to be searchable, the
SEARCH key invokes it.
 The menu choice simply needs a call to onSearchRequested().
 The searchable activity ideally should be declared as singleTop launch
mode.
8
Listening for Fling Gestures
 The possible gestures in the OnGestureListener interface are
 onDown()—Notifies when a tap down event occurs
 onFling()—Notifies when a tap down, movement, and matching up event occurs
 onLongPress()—Notifies when a long press occurs
 onScroll()—Notifies when a scroll occurs
 onShowPress()—Notifies when a tap down occurs before any movement or release
 onSingleTapUp()—Notifies when a tap up event occurs
 When only a subset of gestures are needed, the SimpleOnGestureListener class
can be extended instead.
 It returns false for any of the previous methods not explicitly implemented.
9
Listening for Fling Gestures
 A fling consists of two events: a touch down (the first MotionEvent)
and a release (the second MotionEvent).
 Each motion event has a specified location on the screen given by
an (x,y) coordinate pair, where x is the horizontal axis and y is the
vertical axis.
 The (x,y) velocity of the event is also provided.
10
Using Multi touch
 A multi touch event is when more than one pointer (such as a
finger) touches the screen at the same time.
 This is identified by using a touch listener OnTouchListener, which
receives multiple types of motion events:
 ACTION_DOWN—A press gesture has started with a primary pointer
(finger).
 ACTION_POINTER_DOWN—A secondary pointer (finger) has gone down.
 ACTION_MOVE—A change in press location has changed during a press
gesture.
 ACTION_POINTER_UP—A secondary pointer was released.
 ACTION_UP—A primary pointer was released, and the press gesture has
completed.
11
Style Resource
 A style resource defines the format and look for a UI.
 A style can be applied to an individual View (from within a layout file) or to an entire Activity or
application (from within the manifest file).
 file location : res/values/filename.xml
The filename is arbitrary. The element's name will be used as the resource ID.
 resource reference: In XML: @[package:]style/style_name
 syntax:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style
name="style_name"
parent="@[package:]style/style_to_inherit">
<item
name="[package:]style_property_name"
>style_value</item>
</style>
</resources>
12
Style Resource
 EXAMPLE:
XML file for the style (saved in res/values/):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomText" parent="@style/Text">
<item name="android:textSize">20sp</item>
<item name="android:textColor">#008</item>
</style>
</resources>
XML file that applies the style to a TextView (saved in res/layout/):
<?xml version="1.0" encoding="utf-8"?>
<EditText
style="@style/CustomText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, World!" />
13
Apply a theme to an Activity or application
 To set a theme for all the activities of your application, open the AndroidManifest.xml file and edit
the <application> tag to include the android:theme attribute with the style name. For example:
 <application android:theme="@style/CustomTheme">
 If you want a theme applied to just one Activity in your application, then add
the android:theme attribute to the <activity> tag instead.
 <activity android:theme="@style/CustomTheme">
 Just as Android provides other built-in resources, there are many pre-defined themes that you can
use, to avoid writing them yourself.
 For example, you can use the Dialog theme and make your Activity appear like a dialog box:
 <activity android:theme="@android:style/Theme.Dialog">
 if you want the background to be transparent, use the Translucent theme:
 <activity android:theme="@android:style/Theme.Translucent">
14
Android Animation
 Android provides two types of animation: frame-by-frame and Tween animation.
 Frame by frame animation shows a sequence of pictures in order.
 It enables developers to define the pictures to display, and then show them like a slideshow
 Frame-by-frame animation first needs an animation-list element in the layout file
containing a list of item elements specifying an ordered list of the different pictures to
display.
 <?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/anddev1" android:duration="200" />
<item android:drawable="@drawable/anddev2" android:duration="200" />
<item android:drawable="@drawable/anddev3" android:duration="200" />
</animation-list>
15
Android Animation
 To display the frame-by-frame animation, set the animation to a
view’s background:
 ImageView im = (ImageView) this.findViewById(R.id.myanimated);
im.setBackgroundResource(R.anim.animated);
AnimationDrawable ad = (AnimationDrawable)im.getBackground();
ad.start();
 After the view background is set, a drawable can be retrieved by
calling getBackground() and casting it to
AnimationDrawable.Then, calling the start() method starts the
animation.
16
Android Animation
 Tween animation uses a different approach that creates an animation
by performing a series of transformations on a single image.
 In Android, it provides access to the following classes that are the basis
for all the animations:
 AlphaAnimation—Controls transparency changes
 RotateAnimation—Controls rotations
 ScaleAnimation—Controls growing or shrinking
 TranslateAnimation—Controls position changes
 These four Animation classes can be used for transitions between
activities, layouts, views and so on.
 All these can be defined in the layout XML file as
<alpha>, <rotate>, <scale>,and <translate>.
 They all have to be contained within an AnimationSet <set>
17

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Kürzlich hochgeladen (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

Empfohlen

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Android Training in Bangalore By MobiGnosis

  • 1. Android Bootcamp SESSION 9 – TOUCH EVENTS
  • 2. Agenda  Event Handlers & Event Listeners  Building Menus  Fling Gestures  Multi Touch events  Animation  Styles 2
  • 3. Event Handlers and Event Listeners  Most user interaction with an Android device is captured by the system and sent to a corresponding callback method.  These events can be handled by extending the class and overriding the methods, called event handlers.  User interaction with View or ViewGroup objects can also support event listeners.  For example, the setOnClickListener() event listener can be registered for a button and when it is pressed, the onClick() method is called. 3
  • 4. Intercepting a Physical Key Press 4 Source: Android Cookbook Text Book (Refer Handout)
  • 5. Intercepting a Physical Key Press  The system first sends any KeyEvent to the appropriate callback method in the in-focus activity or view.  These callback methods are :  onKeyUp(), onKeyDown(), onKeyLongPress()—Physical key press callbacks.  onTrackballEvent(), onTouchEvent()—Trackball and touchscreen press callbacks  onFocusChanged()—Called when the view gains or loses focus  These can be overridden by the application to customize with different actions.  For example, to turn off the camera button (to avoid accidental presses), just consume the event in the onKeyDown() callback method for the Activity. 5
  • 6. Intercepting a Physical Key Press  This is done by intercepting the method for the event KeyEvent.KEYCODE_CAMERA and returning true:  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_CAMERA) { return true; // consume event, hence do nothing on camera button } return super.onKeyDown(keyCode, event); }  By consuming the event, it does not get passed on to other Android components.  There are a few exceptions to this:  The Power button and HOME key are intercepted by the system and do not reach the application for customization.  The BACK, MENU, HOME, and SEARCH keys should not intercept the KeyDown but instead the KeyUp. 6
  • 7. Building Menus  A developer can implement three types of menus in Android  Options menu—The main menu for an Activity that displays when the MENU key is pressed.  Context Menu—A floating list of menu items that displays when a view is long pressed.  Submenu—A floating list of menu items that displays when a menu item is pressed.  The Options menu is created the first time the MENU key is pressed in an activity.  This launches the onCreateOptionsMenu() method that usually contains Menu methods, such as:  menu.add(GROUP_DEFAULT, MENU_ADD, 0, "Add") .setIcon(R.drawable.icon); 7
  • 8. Building Menus  the onPrepareOptionsMenu() can be used if any of the menu options need to change during run-time  When an item from the options menu is clicked, the onOptionsItemSelected() method is called.  This passes the selected item ID, and a switch statement can be used to determine which option was selected. Utilizing Search KEY  If an activity in the in-focus application is defined to be searchable, the SEARCH key invokes it.  The menu choice simply needs a call to onSearchRequested().  The searchable activity ideally should be declared as singleTop launch mode. 8
  • 9. Listening for Fling Gestures  The possible gestures in the OnGestureListener interface are  onDown()—Notifies when a tap down event occurs  onFling()—Notifies when a tap down, movement, and matching up event occurs  onLongPress()—Notifies when a long press occurs  onScroll()—Notifies when a scroll occurs  onShowPress()—Notifies when a tap down occurs before any movement or release  onSingleTapUp()—Notifies when a tap up event occurs  When only a subset of gestures are needed, the SimpleOnGestureListener class can be extended instead.  It returns false for any of the previous methods not explicitly implemented. 9
  • 10. Listening for Fling Gestures  A fling consists of two events: a touch down (the first MotionEvent) and a release (the second MotionEvent).  Each motion event has a specified location on the screen given by an (x,y) coordinate pair, where x is the horizontal axis and y is the vertical axis.  The (x,y) velocity of the event is also provided. 10
  • 11. Using Multi touch  A multi touch event is when more than one pointer (such as a finger) touches the screen at the same time.  This is identified by using a touch listener OnTouchListener, which receives multiple types of motion events:  ACTION_DOWN—A press gesture has started with a primary pointer (finger).  ACTION_POINTER_DOWN—A secondary pointer (finger) has gone down.  ACTION_MOVE—A change in press location has changed during a press gesture.  ACTION_POINTER_UP—A secondary pointer was released.  ACTION_UP—A primary pointer was released, and the press gesture has completed. 11
  • 12. Style Resource  A style resource defines the format and look for a UI.  A style can be applied to an individual View (from within a layout file) or to an entire Activity or application (from within the manifest file).  file location : res/values/filename.xml The filename is arbitrary. The element's name will be used as the resource ID.  resource reference: In XML: @[package:]style/style_name  syntax: <?xml version="1.0" encoding="utf-8"?> <resources> <style name="style_name" parent="@[package:]style/style_to_inherit"> <item name="[package:]style_property_name" >style_value</item> </style> </resources> 12
  • 13. Style Resource  EXAMPLE: XML file for the style (saved in res/values/): <?xml version="1.0" encoding="utf-8"?> <resources> <style name="CustomText" parent="@style/Text"> <item name="android:textSize">20sp</item> <item name="android:textColor">#008</item> </style> </resources> XML file that applies the style to a TextView (saved in res/layout/): <?xml version="1.0" encoding="utf-8"?> <EditText style="@style/CustomText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello, World!" /> 13
  • 14. Apply a theme to an Activity or application  To set a theme for all the activities of your application, open the AndroidManifest.xml file and edit the <application> tag to include the android:theme attribute with the style name. For example:  <application android:theme="@style/CustomTheme">  If you want a theme applied to just one Activity in your application, then add the android:theme attribute to the <activity> tag instead.  <activity android:theme="@style/CustomTheme">  Just as Android provides other built-in resources, there are many pre-defined themes that you can use, to avoid writing them yourself.  For example, you can use the Dialog theme and make your Activity appear like a dialog box:  <activity android:theme="@android:style/Theme.Dialog">  if you want the background to be transparent, use the Translucent theme:  <activity android:theme="@android:style/Theme.Translucent"> 14
  • 15. Android Animation  Android provides two types of animation: frame-by-frame and Tween animation.  Frame by frame animation shows a sequence of pictures in order.  It enables developers to define the pictures to display, and then show them like a slideshow  Frame-by-frame animation first needs an animation-list element in the layout file containing a list of item elements specifying an ordered list of the different pictures to display.  <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/anddev1" android:duration="200" /> <item android:drawable="@drawable/anddev2" android:duration="200" /> <item android:drawable="@drawable/anddev3" android:duration="200" /> </animation-list> 15
  • 16. Android Animation  To display the frame-by-frame animation, set the animation to a view’s background:  ImageView im = (ImageView) this.findViewById(R.id.myanimated); im.setBackgroundResource(R.anim.animated); AnimationDrawable ad = (AnimationDrawable)im.getBackground(); ad.start();  After the view background is set, a drawable can be retrieved by calling getBackground() and casting it to AnimationDrawable.Then, calling the start() method starts the animation. 16
  • 17. Android Animation  Tween animation uses a different approach that creates an animation by performing a series of transformations on a single image.  In Android, it provides access to the following classes that are the basis for all the animations:  AlphaAnimation—Controls transparency changes  RotateAnimation—Controls rotations  ScaleAnimation—Controls growing or shrinking  TranslateAnimation—Controls position changes  These four Animation classes can be used for transitions between activities, layouts, views and so on.  All these can be defined in the layout XML file as <alpha>, <rotate>, <scale>,and <translate>.  They all have to be contained within an AnimationSet <set> 17