Android Transition框架使用--介绍(1)
来源:互联网 发布:nginx部署webpack项目 编辑:程序博客网 时间:2024/06/05 06:31
1 介绍
Transition框架提供了一种动画的方法,可以两个view之间切换时有动画效果( overridePendingTransition()方法不一样)。Transition可以让两个View之间的其中一个组件,如TextView之间有动画效果。
2 框架介绍及使用步骤
2.1 开始和结束Scene,代表开始和结束的两个视图
2.2 Transition表示两个Scene之间共享元素的过渡的动画,如fade等。
2.3 TransitionManager传入 结束Scene和Transition,负责执行过渡。
3 Scene的创建
Scene的创建有两种方式:一种是使用new Scene();另一种是Scene.getSceneForLayout()方法。
第一种方法:目前已经过期,但是也还可以使用。
创建代码示例如下:
//get the layout ID RelativeLayout baseLayout = (RelativeLayout)findViewById(R.id.base); //first scene ViewGroup startViews = (ViewGroup)getLayoutInflater() .inflate(R.layout.activity_transition_start2, baseLayout, false); //second scene ViewGroup endViews = (ViewGroup)getLayoutInflater() .inflate(R.layout.activity_transition_end2, baseLayout, false); //create the two scenes scene1 = new Scene(baseLayout, startViews); scene2 = new Scene(baseLayout, endViews);
第二种方式,直接使用布局文件创建:
mSceneRoot=(ViewGroup)findViewById(R.id.scene_root); // Create the scenes scene1 =Scene.getSceneForLayout(mSceneRoot, R.layout.activity_transition_start3,this); scene2 =Scene.getSceneForLayout(mSceneRoot, R.layout.activity_transition_end3,this);从上面示例代码可以看出,第二种方式创建简单,代码较少。
4 Transition
Transition创建也有两种方式,一种是直接在代码里面创建,另一种是在xml创建tansition描述。
第一种创建方式:
transition = new AutoTransition(); // 或者使用new Fade() transition.setDuration(2000); transition.setInterpolator(new AccelerateDecelerateInterpolator());
第二种创建方式:这种方式需要在res文件目录下创建transition目录,在目录下创建fade_transition.xml文件
fade_transition.xml文件内容如下:
<autoTransition xmlns:android="http://schemas.android.com/apk/res/android" android:duration="3000" android:interpolator="@android:interpolator/cycle"/>在Acitivity中创建Transition如下:
transition = TransitionInflater.from(this).inflateTransition(R.transition.fade_transition);// 第一个参数是结束的Scene,第二个参数是第四步定义的Transition动画。
Android自带的Transition动画类型有如下:
至此,Transition框架简单使用就是以上的几个部分。但是在有的时候Transition,并不适用,比如在使用ListView的时候。
- 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
参考:http://developer.android.com/intl/zh-cn/training/transitions/overview.html
- Android Transition框架使用--介绍(1)
- Android Transition框架介绍&使用
- Android Transition框架介绍&使用
- (转)Android Transition框架介绍&使用
- Android Transition框架介绍(1)
- 移动开发指南:Android Transition框架介绍
- Android Transition 和 Activity & Fragment Transition详解(二)--Android Transition框架介绍
- 使用Android.Transition框架创建动画(1)
- Android Transition框架使用--Demo(2)
- Android:Fragment Transition介绍
- 使用Android.Transition框架创建动画(2)
- Android Transition框架(2)-Scene
- Android Litepal框架使用介绍
- android.transition
- Android Transition
- Android Transition
- Android Transition
- Android Transition
- hdu 1421 搬寝室
- 设计模式C++学习笔记之九(Template Method模板方法模式)
- 《跟着小吴哥学python》之 01 python初体验
- ExecutorService线程池的用法
- java 接口Comparable和Comparator的使用
- Android Transition框架使用--介绍(1)
- fedora 16 yum安装mysql后怎样启动,以及添加为系统服务
- IIS的安装部署配置问题
- Volley源码解析,框架综述,使用简述
- 算法竞赛入门经典——习题2.5
- 深入探索C++对象模型笔记
- STL heap底层及使用
- 设计模式C++学习笔记之十(Builder建造者模式)
- OpenStack(4)