Building Apps with Graphics & Animation
1 Displaying Graphics with OpenGL ES
2 Animating Views Using Scenes and Transitions
- user input and other events
- provide visual continuity between view hierarchies
- give users feedback and help them learn how your app works
- transitions framework
2.1 The Transitions Framework
- main features and components
- features:
- Group-level animations
- Transition-based animation
- Built-in animations
- Resource file support
- Lifecycle callbacks
2.1.1 Overview
- many scenes —— view(layout), from a scenes to another scene
- view hierarchies
- start and end scene
TransitionManager
2.2.2 Scenes
- a view hierarchy is a any(simple or complex) view
- generate a view hierarchy dynamically at runtime
- scene root
- create a scene
2.2.3 Transitions
- animations create a series of frames
- the frames depict a change between the view hierarchies of starting and ending scenes
Transition
Object stores the animation, using aTransitionManager
to apply the object- transition between different scenes or a different state of current scene
2.2 Creating a Scene
- store the state of a view hierarchy
2.2.1 Create s Scene From a Layout Resource
- create
Scene
object from a layout res - retrieve the scene root from a layout as a ViewGroup instance
Scene.getSceneForLayout()
2.2.2 Define Layouts for Scenes
- create two different scenes with the same scene root element
- load mulituple unrelated scene objects
- layout definitions:
- main layout with a child layout
- the first scene layout with one text, named “first_scene.xml”
- the second scene layout with another text, named “second_scene.xml”
<LinearLayout>
<FrameLayout android:id="@+id/scene_ root>
<include layout="@layout/a_scene />
</FrameLayout>
</LinearLayout>
2.2.3 Generate Scenes from Layouts
ViewGroup root = (ViewGroup) findViewById(R.id.scene_root);
Scene fristScene = Scene.getSceneForLayout(root, R.layout.first_scene, this);
Scene secondScene = Scene.getSceneForLayout(root, R.layout.second_scene, this);
2.2.4 Create a Scene in Your Code
- use
Scene(sceneRoot, viewHierarchy)
// Obtain the scene root element
ViewGroup sceneRoot = (VIewGroup) mSomeLayoutElement;
// Obtain the view hierarchy to add as a child of the scene root when this scene id entered
ViewGroup viewHierarchy = (ViewGroup) someOtherLayoutElement;
Scene scene = new Scene(sceneRoot, viewHierarchy);
2.2.5 Create Scene Actions
setEnter/ExitAction()
- call
setExitAction()
on the starting scene before running the tranistion animation - call
setEnterAction()
on the ending scene after running the transition animation
2.3 Applying a Transition
- apply a transition between two scenes if a view hierarchy
- animtions create a series of frames of hierarchies chanegs
- animations as transition objects
- run a animation between two scenes using built-in transitions to move, resize and fade views
2.3.1 Create a Transition
- Create a transition instance from a res file
res/transition/fade_transition.xml
<transitionSet android:transitonOrdering="sequential"> <fade android:fadingMode="fade-out" /> <changeBounds /> <fade android:fadingMode="fade_in /> </tranistionSet>
- inflate a Transition instance inside your activty from a res file
Transition fadeTransition = TransitionInflater.from(this).inflateTransition(R.transition.fade_transition);
-
create a transition instance in your code
Transition fadeTransition = new Fade();
2.3.2 Apply a Transition
TransitionManager.go(scene, fadeTransition);