Android_Activity开启动画的设置
2016-04-18 19:54
507 查看
Android开发过程中,很多时候我们需要Activity开启和关闭的时候有一定的动画效果,如何通过配置文件实现动画效果?
一般分为二步:
1、在res资源文件夹下面的anim(没有的话创建一个)创建.xml的动画文件
创建一个从上到下的动画文件top_to_bottom.xml
创建一个从下到上的动画文件bottom_to_top.xml
创建一个从左到右的动画文件top_to_bottom.xml
创建一个从右到左的动画文件top_to_bottom.xml
2、代码中使用
设置启动动画:
PS:不需要状态出现时需要设置activity状态栏透明,在androidmanifest.xml里配置:
android:theme="@android:style/Theme.Translucent"
一般分为二步:
1、在res资源文件夹下面的anim(没有的话创建一个)创建.xml的动画文件
创建一个从上到下的动画文件top_to_bottom.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="200" /> </set>
创建一个从下到上的动画文件bottom_to_top.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="100%p" android:toYDelta="0" <span style="white-space:pre"> </span>android:duration="200" /> </set>
创建一个从左到右的动画文件top_to_bottom.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="400" android:fromXDelta="-100%p" android:toXDelta="0" /> </set>
创建一个从右到左的动画文件top_to_bottom.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="400" android:fromXDelta="0%p" android:toXDelta="-100%p"/> </set>
2、代码中使用
设置启动动画:
Intent intent = new Intent(this,DemoActivity.class); startActivity(intent); overridePendingTransition(R.anim.activity_open,0);设置关闭动画:
finish(); overridePendingTransition(R.anim.bottom_end,0);
PS:不需要状态出现时需要设置activity状态栏透明,在androidmanifest.xml里配置:
android:theme="@android:style/Theme.Translucent"
相关文章推荐
- 解决android-Ultra-Pull-To-Refresh 和ViewPager冲突的问题
- android之Sim Tool Kit流程分析
- 【Android】布局——图片紧随文字
- 将第三方apk编译进Android系统文件system.img
- PRODUCT_COPY_FILES的深入理解,为何不能在Android.mk使用
- Android和IOS系统对比
- 《疯狂的android讲义第3版》读书笔记
- Android Studio 快捷键、插件、基本设置、注意事项
- Android应用程序插件化研究之DexClassLoader
- android中自定义radiobutton的背景色选择默认图标
- android回调的一些总结
- Android资源文件-Shape
- 存储卡路径(接口路径)
- Android Studio 教你在debug调试模式下使用正式签名
- Android Studio开发工具学习篇章一
- Android 判断横屏还是竖屏以及设置方式
- android常用快捷方式
- mac下配置android开发环境
- 关于Android调用invalidate()之后不能及时调用ondraw()的解决办法
- Android开发之DialogFragment