• Android 中 PopupWindow使用


    1 背景置灰: 
         popupWindow = new PopupWindow(menuView, LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT, true);
         第二三个参数必须是LayoutParams.FILL_PARENT,这样才能填充整个屏幕,达到背景置灰的目的。

    2 popupwindow的边框,圆角背景。downbutton_corne.xml

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape
    ="rectangle">
    <gradient android:startColor="#c0000000" android:endColor="#c0000000"
    android:angle
    ="90" /><!--背景颜色渐变 -->
    <stroke android:dashWidth="2dp" android:dashGap="2dp"
    android:width
    ="2dp" android:color="#FF00ff00"></stroke>
    <!--描边 -->
    <corners android:bottomRightRadius="5dp"
    android:bottomLeftRadius
    ="5dp" android:topLeftRadius="5dp"
    android:topRightRadius
    ="5dp" /><!--设置圆角-->
    </shape>

    3 淡入淡出动画 

    popupWindow.setAnimationStyle(R.style.PopupAnimation);
    这条代码是设置style的,动画文件就是在style文件里面引入的。下面是淡入的动画,动画教程网上也很多。淡出的动画就这些参数值交换位置就是了。android:duration这个是持续时间.

    <set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale android:fromXScale="0.6" android:toXScale="1.0"
    android:fromYScale
    ="0.6" android:toYScale="1.0" android:pivotX="50%"
    android:pivotY
    ="50%" android:duration="5000" />
    <alpha android:interpolator="@android:anim/decelerate_interpolator"
    android:fromAlpha
    ="0.0" android:toAlpha="1.0" android:duration="5000" />
    </set>

    4 响应返回键

    new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

    关键在于最后一个参数,ADK 给出的提示是 Focusable,顾名思义就是该 PW 的 Focusable 属性,让它能够接受焦点。

     
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); // 响应返回键必须加上这句

    或者加上按键响应
    在popupwindow的view加上
     setOnKeyListener,就能解决。




  • 相关阅读:
    Java排序算法之堆排序
    servlet学习总结(一)——HttpServletRequest(转载)
    servlet学习总结(一)——初识Servlet
    Java排序算法之快速排序
    Java排序算法之直接选择排序
    第八课、泛型编程简介
    第六课、算法效率的度量
    第四课、程序灵魂的审判
    第三课、初识程序的灵魂------------------------狄泰软件学院
    用solidity语言开发代币智能合约
  • 原文地址:https://www.cnblogs.com/hbf369/p/2289456.html
Copyright © 2020-2023  润新知