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. python3调用阿里云短信服务

    #!/usr/bin/env python#-*- coding:utf-8 -*-#Author:lzd import uuidimport datetimeimport hmacimport ba ...

  2. RouterOS SOCKS代理服务器(官方文档翻译)

    SOCKS 是基于TCP应用层协议穿透防火墙的代理服务器,即使防火墙阻止了一些应用端口,也能通过SOCKS代理穿透.SOCKS协议是独立于应用层的,因此可以用于WWW.FTP.Telnet等等. 来至 ...

  3. 01:zabbix监控redis

    一.zabbix 自动发现并监控redis多实例 1.1 编写脚本 1.1.1 redis_low_discovery.sh 用于发现redis多实例 [root@redis02 homed]# ca ...

  4. python logging 重复写日志问题

    用Python的logging模块记录日志时,遇到了重复记录日志的问题,第一条记录写一次,第二条记录写两次,第三条记录写三次...很头疼,这样记日志可不行.网上搜索到了原因与解决方案: 原因:没有移除 ...

  5. Linux安装imagick扩展出现错误:configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.

    在Linux(CentOS)上安装imagick扩展时,遇到如下错误: checking ImageMagick MagickWand API configuration program... che ...

  6. python中tornado的第一个例子

    1  先安装tornado pip install tornado 2 新建tor.py 记住不能建立 tornado.py 这样的名字  不然会报错 ImportError: No module n ...

  7. DBNavigator中把insert变为append

    procedure TForm1.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);begin    if Button = nbIns ...

  8. 开关 toggleClass('hide')

    toggleClass 实现属性的反转 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  9. oracle 安装包

    Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Microsoft Windows (32-bit ...

  10. StretchBlt

    StretchBlt  函数从源矩形中复制一个位图到目标矩形,必要时按目前目标设备设置的模式进行图像的拉伸或压缩以满足目标矩形的尺寸. 原型: BOOL StretchBlt( HDC hdcDest ...