#Android笔记#popupwindow淡入淡出动画效果的研究

前几天完成了底部菜单栏的设计与功能的实现,其中就包括了其弹出效果的设置,下面就来分析一下:

实现步骤:

1.在res目录下新建anim文件夹用来存放动画相关的xml文件。

123

2.新建xml文件(push_bottom_in.xml,push_bottom_out.xml),写入实现淡入淡出效果的代码:

<?xml version="1.0" encoding="utf-8"?>
<!-- 淡入 -->
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <alpha
        android:duration="200"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

</set>

 

<?xml version="1.0" encoding="utf-8"?>
<!--淡出 -->
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <alpha
        android:duration="200"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />

</set>

 

其中

参数duration用来设置动画完成需要的时间

参数fromAlpha表示动画开始时的透明度

参数toAlpha表示动画结束时的透明度

3.在res->values->styles下编辑淡入淡出效果的style:

 <style name="AnimBottom" parent="@android:style/Animation">
        <item name="android:windowEnterAnimation">@anim/push_bottom_in</item>
        <item name="android:windowExitAnimation">@anim/push_bottom_out</item>
    </style>

其中AnimBottom是style的名字,它的父对象是android:Animation,android:windowEnterAnimation是指窗体的进入动画,andoird:windowExitAnimation是指窗体的离开动画

它们所包裹的就是刚刚定义的那两个xml文件。


4.最后在java代码中调用这个style

this.setAnimationStyle(R.style.AnimBottom);

 

注:以上的过程主要是针对上一篇底部菜单栏的设计而言的,因此可能不具备代表性。不过最近也会对android的动画效果做一定的研究,毕竟用户体验也是很重要的嘛!有兴趣的朋友也可以下载这个demo看一下还是有一定借鉴意义的!

下载地址:http://download.csdn.net/detail/superyu1992/8048515

android 下拉,淡入淡出特效源码 依赖support v7 // /** * PopupWindow上菜单进入动画 */ public static Animation createPopupAnimIn(Context context, int fromYDelta) { AnimationSet animationSet = new AnimationSet(context, null); // animationSet.setInterpolator(new BounceInterpolator()); //结束时弹跳 animationSet.setFillAfter(true); //移动 TranslateAnimation translateAnim = new TranslateAnimation(0, 0, fromYDelta, 20); translateAnim.setDuration(TIME_IN); animationSet.addAnimation(translateAnim); //回弹效果 TranslateAnimation translateAnim2 = new TranslateAnimation(0, 0, 0, -20); translateAnim2.setStartOffset(TIME_IN); translateAnim2.setDuration(TIME_IN_BACK); animationSet.addAnimation(translateAnim2); return animationSet; } /** * PopupWindow上菜单离开动画 */ public static Animation createPopupAnimOut(Context context, int toYDelta) { AnimationSet animationSet = new AnimationSet(context, null); animationSet.setFillAfter(true); TranslateAnimation translateAnim = new TranslateAnimation(0, 0, 0, toYDelta); translateAnim.setDuration(TIME_OUT); animationSet.addAnimation(translateAnim); return animationSet; } /** * PopupWindow背景进入动画(透明度渐变) */ public static Animation createPopupBgFadeInAnim() { AlphaAnimation anim = new AlphaAnimation(0, 1.0f); anim.setDuration(TIME_IN); anim.setFillAfter(true); return anim; } /** * PopupWindow背景离开动画(透明度渐变) */ public static Animation createPopupBgFadeOutAnim(int duration) { AlphaAnimation anim = new AlphaAnimation(1.0f, 0); anim.setDuration(duration); anim.setFillAfter(true); return anim; } /** * PopupWindow按钮点击动画 */ public static Animation createPopupItemBiggerAnim(Context context) { AnimationSet animationSet = new AnimationSet(context, null); animationSet.setFillAfter(true); //放大(设置缩放的中心点为自己的中心) ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); scaleAnim.setDuration(TIME_OUT_CLICK); animationSet.addAnimation(scaleAnim); //渐变 AlphaAnimation alphaAnim = new AlphaAnimation(1.0f, 0); alphaAnim.setInterpolator(new AccelerateInterpolator()); alphaAnim.setDuration(TIME_OUT_CLICK); animationSet.addAnimation(alphaAnim); return animationSet; } /** * PopupWindow按钮点击时其它按钮的动画 */ public static Animation createPopupItemSmallerAnim(Context context) { //放大(设置缩放的中心点为自己的中心) ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 0, 1.0f, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); scaleAnim.setDuration(TIME_OUT_CLICK); scaleAnim.setFillAfter(true); return scaleAnim; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值