Animation总结
Contents
2016/1/2 21:12:38
基本知识
- 在res目录创建anim目录
- 创建标签为set的xml文件
2016/1/2 20:30:58
Style中有@跟无@
无@
android:Animation有@
@android:style/Animation
上述两者等价
2016/1/2 21:06:57
平移动画的理解(translate)

平移动画的属性
<translate android:duration="250" //时间 android:fromYDelta="100%p"//开始Y轴的位置 android:fromXDelta="-100%p"//开始X轴的位置 android:toXDelta="0" //结束轴X的位置 android:toYDelta="0%p" /> //上述代码实现activity 从左下到中间的过程动画
2016/1/2 21:18:44
透明动画的理解
透明动画的属性
<alpha android:fromAlpha="0.0"//开始透明度 android:toAlpha="1.0"//结束透明度 android:duration="200"/>
2015-10-02 17:09:51
如何将activity变成透明Activity
- 在布局里定义好自己的样式。
- 创建一个Activity绑定该布局(setContentView)。
在styles里创建一个style。
<style name="ErinStyle" > <item name="android:windowNoTitle">true</item><!--无标题栏--> <item name="android:windowBackground">@android:color/transparent</item> <!--背景透明--> <item name="android:windowIsTranslucent">true</item><!--去除启动activity黑屏--> <item name="android:backgroundDimEnabled">true</item><!--设置前个activity变暗--> (另外还可以加入动画,默认是右边飞出 通过windowEnterAnimation、windowExitAnimation、windowAnimationStyle属性设置) 目前测试 前两者 无法直接设置在上述style 需要引用style才可以实现 <item name="android:windowAnimationStyle">@style/ErinAnim</item> </style>下面给出上下滑动式动画的配置(必须在style里声明 parent是animation)
<style name="ErinAnim" parent="@android:style/Animation"> <item name="android:windowEnterAnimation">@anim/push_top_in</item> <item name="android:windowExitAnimation">@anim/push_top_out</item> </style>
//这个是弹出 push_top_in
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="0"
android:toYScale="1.0"
android:pivotX="0"
android:pivotY="10%"
android:duration="200" </scale>
//这个是消失 push_top_out
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="1.0"
android:toYScale="0"
android:pivotX="0"
android:pivotY="10%"
android:duration="200" />
4.在配置文件里找到该activity 加入style属性即可。
android:theme="@style/ErinStyle"
如何实现一个对话框Activity(上面右图)
- 写好布局文件 绑定Activity
- 创建style 设置属性parent属性为android:Theme.Dialog(使其默认显示为屏幕中部)
然后设置其不显示标题、透明背景即可(相对于上述 代码简化了很多)
this.setFinishOnTouchOutside(false); //设置对话框activity点击外部不消失
android:theme="@android:style/Theme.Dialog" : Activity显示为对话框模式
android:theme="@android:style/Theme.NoTitleBar" : 不显示应用程序标题栏
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" : 不显示应用程序标题栏,并全屏
android:theme="Theme.Light ": 背景为白色
android:theme="Theme.Light.NoTitleBar" : 白色背景并无标题栏
android:theme="Theme.Light.NoTitleBar.Fullscreen" : 白色背景,无标题栏,全屏
android:theme="Theme.Black" : 背景黑色
android:theme="Theme.Black.NoTitleBar" : 黑色背景并无标题栏
android:theme="Theme.Black.NoTitleBar.Fullscreen" : 黑色背景,无标题栏,全屏
android:theme="Theme.Wallpaper" : 用系统桌面为应用程序背景
android:theme="Theme.Wallpaper.NoTitleBar" : 用系统桌面为应用程序背景,且无标题栏
android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" : 用系统桌面为应用程序背景,无标题栏,全屏
android:theme="Theme.Translucent : 透明背景
android:theme="Theme.Translucent.NoTitleBar" : 透明背景并无标题
android:theme="Theme.Translucent.NoTitleBar.Fullscreen" : 透明背景并无标题,全屏
android:theme="Theme.Panel ": 面板风格显示
android:theme="Theme.Light.Panel" : 平板风格显示
ActivityDialog的总结
经过上述两个透明Activity的实现,可得出总结如下:
如果style设置了parent的属性、则默认布局会显示在中部,并且自动去除进入Activity的黑色界面,如果没有设置,则要在布局文件里设置显示的位置。
透明Activity的Style基本设置是 无标题、透明背景、前一个Activity变暗

