android4.1.2获得屏幕分辨率的方法,其它神马都是浮云!

今天看了launcher的代码,才发现有一个隐藏的方法:    
        Display display = getWindowManager().getDefaultDisplay();
        mScreenPixW = display.getRawWidth();

        mScreenPixH = display.getRawHeight();

这样取得的分辨率为800*480,其他的方法如:

display.getWidth();
display.getHeight();

得到的是可用的分辨率,我的机子为取得为800*444,宽度是对的,但是高度为444,这是因为减去了下边systemUI边框的宽度,实际上为activity可用的高度,因为systemUI总是要显示的,不可能隐藏掉,不过getRawWidth和getRawHeight方法并没有对外公开,我们看源代码中就知道了

    /**
     * Gets the raw width of the display, in pixels.
     * <p>
     * The size is adjusted based on the current rotation of the display.
     * </p>
     * @hide
     */
    public int getRawWidth() {                                                                                                                                 
        int w = getRawWidthNative();
        if (DEBUG_DISPLAY_SIZE) Slog.v(
                TAG, "Returning raw display width: " + w);
        return w;
    }

可以看到@hide,说明这是隐藏的方法,所以我们要用的话,要把代码放到源代码中编译就可以了,否则在eclipse中是出错的哟!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值