zoukankan      html  css  js  c++  java
  • bug_ _Popwindow被魅族手机自带虚拟键挡住完美解决

    ========  1  

    之前做了一个分享的功能,从底部弹出popwindow进行分享,但是由于部分手机自带虚拟键,如魅族X4,所以弹出的popwindow被虚拟键挡住,

    在网上找了好多资料,一些资料说把虚拟键隐藏,却是可以实现,但是总觉得不符合要求。然后又看了一下qq的样式,它弹出的popwindow在虚拟键之上,

    然后就在网上找各种popwindow的demo,最后仔细查看一下代码,才发现是我在设置popwindow的高度的时候将它的高度设置成了wrap_content,这里我觉得有必要给大家说一下fill_parent、wrap_content、match_parent的区别:
    1)fill_parent
    设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间。这跟Windows控件的dockstyle属性大体一致。设置一个顶部布局或控件为fill_parent将强制性让它布满整个屏幕。
    2) wrap_content
    设置一个视图的尺寸为wrap_content将强制性地使视图扩展以显示全部内容。以TextView和ImageView控件为例,设置为wrap_content将完整显示其内部的文本和图像。布局元素将根据内容更改大小。设置一个视图的尺寸为wrap_content大体等同于设置Windows控件的Autosize属性为True。
    3)match_parent
      Android2.2中match_parent和fill_parent是一个意思.两个参数意思一样,match_parent更贴切,于是从2.2开始两个词都可以用。那么如果考虑低版本的使用情况你就需要用fill_parent了
    这里只需要将popwindow的高度设置成match_parent 就完美解决了问题,很高兴有木有。

    ==========  2  我在底部弹出一个popwindow 上面有几个按钮,在其他手机上没有问题,但在魅族手机上 ,取消按钮却被遮挡了  ,大家有遇到这个问题吗?

    前几天刚好遇到过 现奉上解决办法:
            public static int getDpi(Activity activity) {
                    Display display = activity.getWindowManager().getDefaultDisplay();
                    DisplayMetrics dm = new DisplayMetrics();
                    int height = 0;
                    @SuppressWarnings("rawtypes")
                    Class c;
                    try {
                            c = Class.forName("android.view.Display");
                            @SuppressWarnings("unchecked")
                            Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
                            method.invoke(display, dm);
                            height = dm.heightPixels;
                    } catch (Exception e) {
                            e.printStackTrace();
                    }
                    return height;
            }
            public static int[] getScreenWH(Context poCotext) {
                    WindowManager wm = (WindowManager) poCotext
                                    .getSystemService(Context.WINDOW_SERVICE);
                    int width = wm.getDefaultDisplay().getWidth();
                    int height = wm.getDefaultDisplay().getHeight();
                    return new int[] { width, height };
            }
            public static int getVrtualBtnHeight(Context poCotext) {
                    int location[] = getScreenWH(poCotext);
                    int realHeiht = getDpi((Activity) poCotext);
                    int virvalHeight = realHeiht - location[1];
                    return virvalHeight;
            }
    关键是最后一个方法:获取虚拟按键的高度,相信你的pop该弹多高 我就不多说了 都懂得

    加个判断,4.0以上才有
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
                    if (currentapiVersion >= 14) {
                            getWindow().getDecorView().setSystemUiVisibility(
                                            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
                    }

  • 相关阅读:
    如何让研发团队保持敏捷并不断进步?
    敏捷方法适合什么样的团队?
    规模化敏捷中的“三要”和“三不要”
    敏捷开发中如何使用看板方法创造价值
    4.0 初步预计更新内容
    3.0 环境应用(待更新)
    5.0 Genymotion安装以及基础使用
    2.0 python+appium环境搭建
    1.0 python-client以及ui自动化介绍
    教你一招另辟蹊径抓取美团火锅数据
  • 原文地址:https://www.cnblogs.com/awkflf11/p/5342579.html
Copyright © 2011-2022 走看看