方便的布局动画
2015-07-08 10:50
85 查看
如果要求自己的Activity整齐划一,可以考虑使用布局动画LayoutAnimation,话不多说,先演示在代码中使用,然后是xml。
接下来在代码中调用该方法即可:
接下来在res/animator目录下新建一个布局动画文件layout-anim.xml:
然后在需要动画的Layout下加入下面一条语句即可:
1.in code
他山之石,可以攻玉,摘抄网友的代码:/** * Layout动画 * * @return */ protected LayoutAnimationController getAnimationController() { int duration=300; AnimationSet set = new AnimationSet(true); Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(duration); set.addAnimation(animation); animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f); animation.setDuration(duration); set.addAnimation(animation); LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f); //注意这个地方是以秒为单位,是浮点型数据,所以要加f controller.setOrder(LayoutAnimationController.ORDER_NORMAL); return controller; }
接下来在代码中调用该方法即可:
listView = (ListView) findViewById(R.id.listView); listView.setLayoutAnimation(getAnimationController()); adapter = new ListViewAdapter(stores); listView.setAdapter(adapter);
2.in xml
首先在res/anim目录下新建一个动画xml文件push_right_in.xml:<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="500" android:fromXDelta="100%p" android:toXDelta="0" /> <alpha android:duration="500" android:fromAlpha="0.0" android:toAlpha="1.0" /> </set>
接下来在res/animator目录下新建一个布局动画文件layout-anim.xml:
<?xml version="1.0" encoding="utf-8"?> <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="0.5"//注意此处单位为s android:animationOrder="random" android:animation="@anim/push_right_in" />
然后在需要动画的Layout下加入下面一条语句即可:
android:layoutAnimation="@animator/layout-anim"
相关文章推荐
- plsql dev中Dynamic Performance Tables not accessible分析解决
- framework7学习笔记
- JAAS授权
- Contains Duplicate
- [欧拉] poj 2513 Colored Sticks
- C#程序设计开发总结(猜猜看游戏开发)
- 悟空学Linux专栏----第6篇
- C++中的内存分区介绍
- Xcode unable to dequeue a cell with identifier
- Contains Duplicate II
- 云计算平台最核心的五项技术
- wamp环境 安装memcached具体操作
- 门面(Facade)模式
- android菜鸟学习笔记16----Android项目打包安装过程(Run as Android Application)
- SVM介绍
- libevent学习资料
- Android Studio设置或更改SDK
- NTFS For Mac 破解版下载
- C语言常见面试题(经典中的经典)
- android状态机statemachine详解