zoukankan      html  css  js  c++  java
  • 让 Popwindow 向上弹出

     1 /**
     2      * 获取父控件的位置y-popwindow的高度 = 应该显示的y坐标.   x这里设置为center 不刻意指定坐标  注意:控件坐标永远是 左上角坐标!
     3      * 
     4      * @param parent
     5      */
     6     public void showUp(View parent) {
     7 
     8         int[] location = new int[2];
     9 
    10         parent.getLocationOnScreen(location);
    11         popupWindow.setFocusable(true);
    12         popupWindow.setOutsideTouchable(true);
    13 
    14         popupWindow.setAnimationStyle(R.style.AnimationPopup);
    15         popupWindow.showAtLocation(parent, Gravity.CENTER_HORIZONTAL
    16                 | Gravity.TOP, 0, location[1] - popupWindow.getHeight() + 20);
    17 
    18       
    19 
    20         popupWindow.update();
    21     }

    valuesstyle.xml:

    1 <resources>
    2 <style name="AnimationPopup">
    3     <item name="@android:windowEnterAnimation">@anim/appear</item>
    4     <item name="@android:windowExitAnimation">@anim/disappear</item>
    5 </style>
    6 </resources>

    animappear.xml

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <set xmlns:android="http://schemas.android.com/apk/res/android" >
     3 
     4 
     5     <scale
     6         android:duration="500"
     7         android:fromXScale="1.0"
     8         android:fromYScale="0.5"
     9         android:pivotX="0%"
    10         android:pivotY="100%"
    11         android:toXScale="1"
    12         android:toYScale="1" />
    13 
    14 
    15     <alpha
    16         android:duration="500"
    17         android:fromAlpha="0.5"
    18         android:interpolator="@android:anim/accelerate_interpolator"
    19         android:toAlpha="1.0" />
    20 
    21 
    22 </set>

    animdisappear.xml

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <set xmlns:android="http://schemas.android.com/apk/res/android" >
     3 
     4 
     5     <scale
     6         android:duration="500"
     7         android:fromXScale="1.0"
     8         android:fromYScale="1"
     9         android:pivotX="0%"
    10         android:pivotY="100%"
    11         android:toXScale="1"
    12         android:toYScale="0.5" />
    13 
    14 
    15     <alpha
    16         android:duration="500"
    17         android:fromAlpha="1.0"
    18         android:interpolator="@android:anim/accelerate_interpolator"
    19         android:toAlpha="0.0" />
    20 
    21 
    22 </set>

    点击屏幕其他部分实现使其消失的功能需要在showAtLocation方法调用前设置下面代码:

    1 pop.setBackgroundDrawable(new PaintDrawable());
    2         pop.setOutsideTouchable(true);
  • 相关阅读:
    KVC笔记
    在iOS工程中引入C++静态库
    看了iOS 7和Xcode 5后的感想
    OpenGL学习第一天
    常用iOS游戏开发工具与SDK
    分享一个技巧,利用批处理调用ruby脚本(可能你为路径苦恼)
    ruby酷酷的方法——另一种next
    ruby的字符串性能到底如何最佳
    ruby元编程之 method_missing 一个细节
    ruby的继承到底可以继承哪些东西
  • 原文地址:https://www.cnblogs.com/l2rf/p/4088839.html
Copyright © 2011-2022 走看看