android-Animating Views Using Scenes and Transitions
来源:互联网 发布:网络教育学位证能买吗 编辑:程序博客网 时间:2024/04/29 10:17
Android includes the transitions framework, which enables you to easily animate changes between two view hierarchies.
Note: For Android versions earlier than 4.4.2 (API level 19) but greater than or equal to Android 4.0 (API level 14), use the animateLayoutChanges
attribute to animate layouts. To learn more, see Property Animation andAnimating Layout Changes.
To help you animate a change between one view hierarchy and another, Android provides the transitions framework.
》The trasnations framework has the following features:
Information about the animation is stored in a Transition
object. To run the animation, you apply the transition using a TransitionManager
instance. The framework can transition between two different scenes or transition to a different state for the current scene.
You can also define your own custom transitions to create an animation effect using the APIs in the animations framework. The transitions framework also enables you to combine different animation effects in a transition set that contains a group of individual built-in or custom transitions.
This section lists some known limitations of the transitions framework:
- Animations applied to a
SurfaceView
may not appear correctly.SurfaceView
instances are updated from a non-UI thread, so the updates may be out of sync with the animations of other views. - Some specific transition types may not produce the desired animation effect when applied to a
TextureView
. - Classes that extend
AdapterView
, such asListView
, manage their child views in ways that are incompatible with the transitions framework. If you try to animate a view based onAdapterView
, the device display may hang. - If you try to resize a
TextView
with an animation, the text will pop to a new location before the object has completely resized. To avoid this problem, do not animate the resizing of views that contain text.
Generate Scenes from Layouts
Scene mAScene;Scene mAnotherScene;// Create the scene root for the scenes in this appmSceneRoot = (ViewGroup) findViewById(R.id.scene_root);// Create the scenesmAScene = Scene.getSceneForLayout(mSceneRoot, R.layout.a_scene, this);mAnotherScene = Scene.getSceneForLayout(mSceneRoot, R.layout.another_scene, this);
Create a Scene in Your Code
Scene mScene;// Obtain the scene root elementmSceneRoot = (ViewGroup) mSomeLayoutElement;// Obtain the view hierarchy to add as a child of// the scene root when this scene is enteredmViewHierarchy = (ViewGroup) someOtherLayoutElement;// Create a scenemScene = new Scene(mSceneRoot, mViewHierarchy);
To provide custom scene actions, define your actions as Runnable
objects and pass them to theScene.setExitAction()
or Scene.setEnterAction()
methods. The framework calls the setExitAction()
method on the starting scene before running the transition animation and the setEnterAction()
method on the ending scene after running the transition animation.
Note: Do not use scene actions to pass data between views in the starting and ending scenes. For more information, see Defining Transition Lifecycle Callbacks.
> In the transitions framework, animations create a series of frames that depict a change between the view hierarchies in the starting and ending scenes.The following code snippet shows how to inflate a Transition
instance inside your activity from a resource file:
Transition mFadeTransition = TransitionInflater.from(this). inflateTransition(R.transition.fade_transition);
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android" android:transitionOrdering="sequential"> <fade android:fadingMode="fade_out" /> <changeBounds /> <fade android:fadingMode="fade_in" /></transitionSet>
private TextView mLabelText;private Fade mFade;private ViewGroup mRootView;...// Load the layoutthis.setContentView(R.layout.activity_main);...// Create a new TextView and set some View propertiesmLabelText = new TextView();mLabelText.setText("Label").setId("1");// Get the root view and create a transitionmRootView = (ViewGroup) findViewById(R.id.mainLayout);mFade = new Fade(IN);// Start recording changes to the view hierarchyTransitionManager.beginDelayedTransition(mRootView, mFade);// Add the new TextView to the view hierarchymRootView.addView(mLabelText);// When the system redraws the screen to show this update,// the framework will animate the addition as a fade in》 To create a custom transition, add a class to your project that extends the
Transition
class and override the methods shown in the following snippet:public class CustomTransition extends Transition { @Override public void captureStartValues(TransitionValues values) {} @Override public void captureEndValues(TransitionValues values) {} @Override public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {}}
- android-Animating Views Using Scenes and Transitions
- Animating Views Using Scenes and Transitions ---
- Animating Views Using Scenes and Transitions - The Transitions Framework
- Animating Views Using Scenes and Transitions ? - Creating Custom Transitions
- Animating Views Using Scenes and Transitions - Creating a Scene
- Animating Views Using Scenes and Transitions - Applying a Transition
- 使用Scenes和Transitions执行动画 -- Animating Views Using Scenes and Transitions
- Animating Views and Windows
- Android动画之使用Scenes和Transitions
- Android 知识要点整理(11)----Scenes and Transitions(场景和变换)
- Scenes and Transitions(1)——转换框架
- Scenes and Transitions(2)——创建场景
- A List itemRenderer using States and Transitions
- Android LayoutInflater - Dynamically Add and Remove Views using Java code
- Android:Using shared element transitions in fragments
- 动画学习2 Animating Views
- Using Data Dictionary and Dynamic Performance Views
- 使用Scenes和Transitions实现View动画
- 嵌入式软件设计中关键字:const/volatile/static
- iOS解决呼出键盘遮挡页面问题(装逼模式一)
- HTML5获取位置信息
- mongodb用户管理
- Start...........
- android-Animating Views Using Scenes and Transitions
- 【虫师--系列03】性能测试知多少----性能测试分类之我见
- 图表部件设置成员小数位数简介
- TextView中文字的省略显示
- centos7 伪分布hadoop安装
- Android官方Training阅读笔记 ---- Managing the Activity Lifecycle(Pausing and Resuming an Activity) (二)
- 音频术语
- iOS深入学习(再谈block)
- win7 64位 修复便签 无法使用错误