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

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

3.直接上代码:

  

 public class MainActivity extends Activity implements OnClickListener {

     private LinearLayout layout1, layout2;
private Button btnShow, btnHint; private int screenWidth, screenHeight; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
addListener(); } private void addListener() {
btnShow.setOnClickListener(this);
btnHint.setOnClickListener(this);
} private void initView() {
screenWidth = getWindowWidth(MainActivity.this);
screenHeight = getWindowHeigh(MainActivity.this);
layout1 = (LinearLayout) findViewById(R.id.layout1);
btnShow = (Button) findViewById(R.id.layout_button);
layout2 = (LinearLayout) findViewById(R.id.layout2);
btnHint = (Button) findViewById(R.id.btnhint);
} @SuppressLint("NewApi")
private void initShowMeanuAnimation() { System.out.println("执行没有");
ObjectAnimator animator1 = ObjectAnimator.ofFloat(layout1, "scaleX",
1.0f, 0.8f);
animator1.setDuration(350);
ObjectAnimator animator2 = ObjectAnimator.ofFloat(layout1, "scaleY",
1.0f, 0.8f);
animator2.setDuration(350);
ObjectAnimator animator3 = ObjectAnimator.ofFloat(layout1, "alpha",
1.0f, 0.5f);
animator3.setDuration(350);
ObjectAnimator animator4 = ObjectAnimator.ofFloat(layout1, "rotationX",
0f, 12f);
animator4.setDuration(200);
ObjectAnimator animator5 = ObjectAnimator.ofFloat(layout1, "rotationX",
12f, 0f);
animator5.setDuration(300);
animator5.setStartDelay(250);
ObjectAnimator animator6 = ObjectAnimator.ofFloat(layout1,
"translationY", 0, -screenHeight * 0.1f);
animator6.setDuration(350); ObjectAnimator animator7 = ObjectAnimator.ofFloat(layout2,
"translationY", 300, 0);
animator7.setDuration(350); animator7.addListener(new AnimatorListenerAdapter() { @Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation); layout2.setVisibility(View.VISIBLE); } }); AnimatorSet set = new AnimatorSet();
set.playTogether(animator1, animator2, animator3, animator4, animator5,
animator6, animator7); set.start();
} /**
* 隐藏PopupWindow
*/
@SuppressLint("NewApi")
public void initHideMeanuAnimation() { ObjectAnimator animator1 = ObjectAnimator.ofFloat(layout1, "scaleX",
0.8f, 1.0f);
animator1.setDuration(350);
ObjectAnimator animator2 = ObjectAnimator.ofFloat(layout1, "scaleY",
0.8f, 1.0f);
animator2.setDuration(350);
ObjectAnimator animator3 = ObjectAnimator.ofFloat(layout1, "alpha",
0.5f, 1.0f);
animator3.setDuration(350);
ObjectAnimator animator4 = ObjectAnimator.ofFloat(layout1, "rotationX",
0f, 12f);
animator4.setDuration(200);
ObjectAnimator animator5 = ObjectAnimator.ofFloat(layout1, "rotationX",
12f, 0f);
animator5.setDuration(300);
animator5.setStartDelay(250);
ObjectAnimator animator6 = ObjectAnimator.ofFloat(layout1,
"translationY", -screenHeight * 0.1f, 0);
animator6.setDuration(350); ObjectAnimator animator7 = ObjectAnimator.ofFloat(layout2,
"translationY", 0, 300);
animator7.setDuration(350); animator7.addListener(new AnimatorListenerAdapter() { @Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
layout2.setVisibility(View.INVISIBLE); } }); AnimatorSet set1 = new AnimatorSet();
set1.playTogether(animator1, animator2, animator3, animator4,
animator5, animator6, animator7); set1.start(); } @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.layout_button:
initShowMeanuAnimation();
break;
case R.id.btnhint:
initHideMeanuAnimation();
break; } } public static int getWindowWidth(Context context) {
// 获取屏幕分辨率
WindowManager wm = (WindowManager) (context
.getSystemService(Context.WINDOW_SERVICE));
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm);
int mScreenWidth = dm.widthPixels;
return mScreenWidth; } public static int getWindowHeigh(Context context) {
// 获取屏幕分辨率
WindowManager wm = (WindowManager) (context
.getSystemService(Context.WINDOW_SERVICE));
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm);
int mScreenHeigh = dm.heightPixels;
return mScreenHeigh;
}
}

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

源码下载:下载

Android 属性动画实现一个简单的PopupWindow的更多相关文章

  1. Android属性动画之ValueAnimation

    ValueAnimation是ObjectAnimation类的父类,经过前几天的介绍,相信大家对ObjectAnimation有了 一定的认识,今天就为大家最后介绍一下ValueAnimation, ...

  2. Android属性动画完全解析(下)

    转载:http://blog.csdn.net/guolin_blog/article/details/44171115 大家好,欢迎继续回到Android属性动画完全解析.在上一篇文章当中我们学习了 ...

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

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

  4. Android属性动画完全解析(中)

    转载:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法,当然也是 ...

  5. Android属性动画完全解析(上)

    Android属性动画完全解析(上) 转载:http://blog.csdn.net/guolin_blog/article/details/43536355 在手机上去实现一些动画效果算是件比较炫酷 ...

  6. Android 属性动画(Property Animation) 全然解析 (下)

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38092093 上一篇Android 属性动画(Property Animatio ...

  7. Android 属性动画 源码解析 深入了解其内部实现

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/42056859,本文出自:[张鸿洋的博客] 我参加了博客之星评选,如果你喜欢我的博 ...

  8. Android属性动画完全解析(下),Interpolator和ViewPropertyAnimator的用法

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/44171115 大家好,欢迎继续回到Android属性动画完全解析.在上一篇文章当中 ...

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

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法 ...

随机推荐

  1. Java 字符串 String

    什么是Java中的字符串 在 Java 中,字符串被作为 String 类型的对象处理. String 类位于 java.lang 包中.默认情况下,该包被自动导入所有的程序. 创建 String 对 ...

  2. 十.jQuery源码分析之.map()

    763行:三个参数. elems:待遍历的数组或对象. callback:回调函数,会在数组的每个元素或对象的每个属性上执行.执行时传入两个参数:数组元素,元素下标;或属性名,属性值. arg:仅限于 ...

  3. 自定义Hibernate Validator约束

    定义注解 实现一个只能输入指定状态的约束条件 import javax.validation.Constraint; import javax.validation.Payload; import j ...

  4. springboot 2.0 自动装配原理 以redis为例

    当面试管问你springboot 和 普通spring 有什么区别? 您还在回答: 简化了配置 ,内置tomcat 等等 吗 ? 那只是皮毛, 最重要的还是自动化配置.一起来了解一下 第一步: 第二步 ...

  5. 阿里云短信接口python版本

    # -*- coding: utf-8 -*- #!/usr/bin/python #encoding=utf-8 import sys from aliyunsdkdysmsapi.request. ...

  6. ASP.NET AJAX web chat application

    ASP.NET AJAX web chat application The project illustrates how to design a simple AJAX web chat appli ...

  7. js网页倒计时精确到秒级

    网页实时倒计时,精确到秒级,和天数倒计时原理一样. 一个很好用的js倒计时!网页实时倒计时,精确到秒级,和天数倒计时原理一样.js倒计时一般用于商城网站团购,特卖,很多地方都可用到!希望能够给大家带来 ...

  8. jQuery用FormData对象实现文件上传以及如何通过ajax下载文件

    之前在Vue的项目里面用到过文件上传,封装好的组件用起来比较顺手,查询Element-UI文档,十八般武器样样都有,一顿操作猛如虎,一看--跑偏了(⊙o⊙)-,我的意思就是用框架实现比较简单,但是如果 ...

  9. could not be installed at this time

    无法下载应用 此时无法安装 Unable to Download App ''App" could not be installed at this time 编译程序的时候,Target ...

  10. 使用WebLogic时控制台输出中文乱码解决方法

    使用WebLogic时控制台输出中文乱码解决方法 1.找到weblogic安装目录,当前项目配置的domain 2.找到bin下的setDomainEnv.cmd文件 3.打开文件,从文件最后搜索第一 ...