1.今天看到一个PopupWindow的效果如图:

2.其实就是属性动画的一个简单实用就ObjectAnimator就可以的,想实现更多,更灵活的可以用ValueAnimator

3.直接上代码:

  

  1 public class MainActivity extends Activity implements OnClickListener {
  2
  3     private LinearLayout layout1, layout2;
  4     private Button btnShow, btnHint;
  5
  6     private int screenWidth, screenHeight;
  7
  8     @Override
  9     protected void onCreate(Bundle savedInstanceState) {
 10         super.onCreate(savedInstanceState);
 11         setContentView(R.layout.activity_main);
 12         initView();
 13         addListener();
 14
 15     }
 16
 17     private void addListener() {
 18         btnShow.setOnClickListener(this);
 19         btnHint.setOnClickListener(this);
 20     }
 21
 22     private void initView() {
 23         screenWidth = getWindowWidth(MainActivity.this);
 24         screenHeight = getWindowHeigh(MainActivity.this);
 25         layout1 = (LinearLayout) findViewById(R.id.layout1);
 26         btnShow = (Button) findViewById(R.id.layout_button);
 27         layout2 = (LinearLayout) findViewById(R.id.layout2);
 28         btnHint = (Button) findViewById(R.id.btnhint);
 29     }
 30
 31     @SuppressLint("NewApi")
 32     private void initShowMeanuAnimation() {
 33
 34         System.out.println("执行没有");
 35         ObjectAnimator animator1 = ObjectAnimator.ofFloat(layout1, "scaleX",
 36                 1.0f, 0.8f);
 37         animator1.setDuration(350);
 38         ObjectAnimator animator2 = ObjectAnimator.ofFloat(layout1, "scaleY",
 39                 1.0f, 0.8f);
 40         animator2.setDuration(350);
 41         ObjectAnimator animator3 = ObjectAnimator.ofFloat(layout1, "alpha",
 42                 1.0f, 0.5f);
 43         animator3.setDuration(350);
 44         ObjectAnimator animator4 = ObjectAnimator.ofFloat(layout1, "rotationX",
 45                 0f, 12f);
 46         animator4.setDuration(200);
 47         ObjectAnimator animator5 = ObjectAnimator.ofFloat(layout1, "rotationX",
 48                 12f, 0f);
 49         animator5.setDuration(300);
 50         animator5.setStartDelay(250);
 51         ObjectAnimator animator6 = ObjectAnimator.ofFloat(layout1,
 52                 "translationY", 0, -screenHeight * 0.1f);
 53         animator6.setDuration(350);
 54
 55         ObjectAnimator animator7 = ObjectAnimator.ofFloat(layout2,
 56                 "translationY", 300, 0);
 57         animator7.setDuration(350);
 58
 59         animator7.addListener(new AnimatorListenerAdapter() {
 60
 61             @Override
 62             public void onAnimationStart(Animator animation) {
 63                 super.onAnimationStart(animation);
 64
 65                 layout2.setVisibility(View.VISIBLE);
 66
 67             }
 68
 69         });
 70
 71         AnimatorSet set = new AnimatorSet();
 72         set.playTogether(animator1, animator2, animator3, animator4, animator5,
 73                 animator6, animator7);
 74
 75         set.start();
 76     }
 77
 78     /**
 79      * 隐藏PopupWindow
 80      */
 81     @SuppressLint("NewApi")
 82     public void initHideMeanuAnimation() {
 83
 84         ObjectAnimator animator1 = ObjectAnimator.ofFloat(layout1, "scaleX",
 85                 0.8f, 1.0f);
 86         animator1.setDuration(350);
 87         ObjectAnimator animator2 = ObjectAnimator.ofFloat(layout1, "scaleY",
 88                 0.8f, 1.0f);
 89         animator2.setDuration(350);
 90         ObjectAnimator animator3 = ObjectAnimator.ofFloat(layout1, "alpha",
 91                 0.5f, 1.0f);
 92         animator3.setDuration(350);
 93         ObjectAnimator animator4 = ObjectAnimator.ofFloat(layout1, "rotationX",
 94                 0f, 12f);
 95         animator4.setDuration(200);
 96         ObjectAnimator animator5 = ObjectAnimator.ofFloat(layout1, "rotationX",
 97                 12f, 0f);
 98         animator5.setDuration(300);
 99         animator5.setStartDelay(250);
100         ObjectAnimator animator6 = ObjectAnimator.ofFloat(layout1,
101                 "translationY", -screenHeight * 0.1f, 0);
102         animator6.setDuration(350);
103
104         ObjectAnimator animator7 = ObjectAnimator.ofFloat(layout2,
105                 "translationY", 0, 300);
106         animator7.setDuration(350);
107
108         animator7.addListener(new AnimatorListenerAdapter() {
109
110             @Override
111             public void onAnimationEnd(Animator animation) {
112                 super.onAnimationEnd(animation);
113                 layout2.setVisibility(View.INVISIBLE);
114
115             }
116
117         });
118
119         AnimatorSet set1 = new AnimatorSet();
120         set1.playTogether(animator1, animator2, animator3, animator4,
121                 animator5, animator6, animator7);
122
123         set1.start();
124
125     }
126
127     @Override
128     public void onClick(View v) {
129         switch (v.getId()) {
130         case R.id.layout_button:
131             initShowMeanuAnimation();
132             break;
133         case R.id.btnhint:
134             initHideMeanuAnimation();
135             break;
136
137         }
138
139     }
140
141     public static int getWindowWidth(Context context) {
142         // 获取屏幕分辨率
143         WindowManager wm = (WindowManager) (context
144                 .getSystemService(Context.WINDOW_SERVICE));
145         DisplayMetrics dm = new DisplayMetrics();
146         wm.getDefaultDisplay().getMetrics(dm);
147         int mScreenWidth = dm.widthPixels;
148         return mScreenWidth;
149
150     }
151
152     public static int getWindowHeigh(Context context) {
153         // 获取屏幕分辨率
154         WindowManager wm = (WindowManager) (context
155                 .getSystemService(Context.WINDOW_SERVICE));
156         DisplayMetrics dm = new DisplayMetrics();
157         wm.getDefaultDisplay().getMetrics(dm);
158         int mScreenHeigh = dm.heightPixels;
159         return mScreenHeigh;
160     }
161 }

代码有重复的地方就没有合并了。

源码下载:下载

转载于:https://www.cnblogs.com/liangstudyhome/p/4467265.html

Android 属性动画实现一个简单的PopupWindow相关推荐

  1. Android属性动画 ObjectAnimator

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/118709616 本文出自[赵彦军的博客] 文章目录 ObjectAnimator ...

  2. (转)Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法

    版权声明:本文出自郭霖的博客,转载必须注明出处. 目录(?)[-] ValueAnimator的高级用法 ObjectAnimator的高级用法 转载请注明出处:http://blog.csdn.ne ...

  3. android 属性动画实例,Android属性动画完全解析 中 ,ValueAnimator和ObjectAnimator的高级用法...

    大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法,当然也是最常用的一些用法,这些用法足以覆盖我们平时大多情况下的动画需求了.但是,正如上篇文章当中所说到的,属性动画对补间动画进行了 ...

  4. Android 系统(196)---Android 属性动画

    Android 属性动画 属性动画 总结&攻略 前言 动画的使用 是 Android 开发中常用的知识 本文将详细介绍 Android 动画中 属性动画的原理 & 使用 动画类型 关于 ...

  5. android+属性动画+高度,android 自定义view+属性动画实现充电进度条

    近期项目中需要使用到一种类似手机电池充电进度的动画效果,以前没学属性动画的时候,是用图片+定时器的方式来完成的,最近一直在学习动画这一块,再加上复习一下自定义view的相关知识点,所以打算用属性动画和 ...

  6. Android 属性动画 详解

    Android 属性动画 详解 Android动画类型: View Animation(即所谓的Tween Animation补间动画):View Animation相当简单,不过只能支持简单的缩放. ...

  7. Android 属性动画详解

    Component 是一个强大的.完善的组件化框架. 欢迎大家使用 请尊重别人劳动成果         转载请注明出处:http://blog.csdn.net/u011692041/article/ ...

  8. Android属性动画完全解析(上),初识属性动画的基本用法

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系 ...

  9. Android属性动画完全解析(上),初识属性动画的基本用法(转)

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系 ...

  10. Android属性动画深入分析:让你成为动画牛人

    转载请注明出处: http://blog.csdn.net/singwhatiwanna/article/details/17841165 前言 感谢你阅读本文,我坚信读完本文肯定不会让你失望的.想要 ...

最新文章

  1. android 带记忆功能的播放器源码,Android实现阅读进度记忆功能
  2. Python使用matplotlib可视化柱状图、坐标轴标签的符号(-)显示为了方框□□、设置rcParams参数配置解决
  3. 独家 | 一文带你读懂特征工程!
  4. CSS 工程化 小结
  5. 科学计算库Numpy——随机模块
  6. xp,win7,win2003,win2008常用命令集
  7. 项目管理中,最难管的是什么?(转)
  8. 【题解】【数组】【Prefix Sums】【Codility】Genomic Range Query
  9. 剑指offer(21)栈的压入、探出序列
  10. 老华为可以升级鸿蒙,真良心!五年前老机型都能升级华为鸿蒙
  11. lnmp修改mysql上传大小限制_安装Linux+Nginx+MySQL+PHP(LNMP)集成环境,解除上传文件大小限制...
  12. 漫画:如何给女朋友解释什么是系统可用性?| 技术头条
  13. 商场收银系统服务器安装在哪里,收银系统怎么安装?详细步骤分享
  14. 计算机软件著作权登记
  15. html页面显示不全问题,网页显示不完全
  16. 解决方案:LoadLibrary加载动态库失败,错误代码126
  17. 方便面又好卖了!康师傅天猫618狂增10倍,还说这只是起点
  18. android 触摸板 鼠标,您的Android手机或iPhone的光滑触摸屏面板可用于控制Mac OS上的鼠标指针...
  19. nginx实现多个域名在同一服务器指向不同端口
  20. 如何调用腾讯的IP库?

热门文章

  1. 携号转网不会有多大影响
  2. 解决办法:无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系
  3. 路面压电发电,应该有前途
  4. 一以贯之是一个思想家成熟的标志
  5. LINUX下载编译jpeglib
  6. 在SSD上安装WINDOWS 10,启动时有可能卡死
  7. C++ 中两个数据交换总结
  8. python怎么批量下载图片_python批量下载图片的三种方法
  9. 出现画面抖动_手机拍照时模糊,抖动?赶紧来拯救你的拍摄技术吧!
  10. 深入浅出mfc之6大技术 运行时类型识别 DCLARE_DYNCREATE、DECLARE_DYNAMIC 、DECLARE_SERIAL、RUNTIME_CLASS、DECLARE_SERIAL 等