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. 面试总结之数据结构(Data Structure)

    常用数据结构及复杂度 http://www.cnblogs.com/gaochundong/p/3813252.html 常用数据结构的时间复杂度 Data Structure Add Find De ...

  2. [java]经验集

    Calendar c = Calendar.getInstance(); c.set(1999,12,21); SimpleDateFormat sdf = new SimpleDateFormat( ...

  3. MVC中@Html.Action的用法

    MVC项目中如果有公共部分的代码就可以单独拿出来作为控件来用(比如头部和底部代码).跟ASP.NET中的ASCX实现的效果一样,但MVC比它方便的多. 想要实现该效果,需要知道@Html.Action ...

  4. Node.js 项目打包

    Node项目基于Electron打包 Electron打包打包后项目.exe程序包含在文件夹中,基于Electron打包的基础上直接打包成exe程序 参考一 参考二 需求的软件环境: NSIS 2.4 ...

  5. redis一主二从三哨兵

    redis做集群的时候有很多种配置方法,一主二从三哨兵这种模式是官网推荐的.,写配置文件链接的时候,写的是哨兵地址,不是IP,用户名,密码之类的. 一主二从很好理解,一个主的redis,实时备份到两个 ...

  6. clr相关名词

    程序集:一个或多个类型定义文件和资源文件的集合 Native Code(本机代码): 已被编译为特定于处理器的机器码的代码. 本地代码(native code)是计算机编程(代码),编译用来运行一个特 ...

  7. 若p是与10互质的质数,则p-1个9能被p整除

    [若p是与10互质的质数,则k(p-1)个9能被p整除] 因为(p,10)=1,所以(p,10^k)=1.根据费马定理,10^(k*(p-1))-1|p. 而10^k*(p-1)-1是一个位数为(p- ...

  8. 再谈C#编码规范

    编码规范是老生常谈的问题,现在再看代码规范可能不会再去在意变量,控件的命名方法等,而是更加关注代码的实用性. 首先我们要明白一下几点, 1.代码写出来除了让他跑起来还有个非常非常重要的作用是维护,因为 ...

  9. java关于密码的加密解密

    密码的加密方法有多种,常见的为Aes.Md5 Aes加密,可逆. 其中,Md5加密是采用了散列算法,也就是哈希算法,可以进行多次散列加密.Md5加密是不可逆的,无法解密. MD5是不可逆的单向加密方式 ...

  10. oracle 求班级平均分

    select * from ( selectclass 班级,subject,avg(grade) avg_gradefrom student_score group by class,subject ...