如何在Android中获取可用的屏幕宽度和高度 [英] How to get USABLE screen width and height in Android

查看:926
本文介绍了如何在Android中获取可用的屏幕宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个我真正需要知道正确屏幕尺寸的应用程序.实际上,我知道该怎么做...但是出现了一个问题,因为即使您执行requestWindowFeature(Window.FEATURE_NO_TITLE);,此操作也是如此:

I'm creating an app where I really need to know the correct screen dimensions. Actually I know how to do that... but a problem appeared, because even if you dorequestWindowFeature(Window.FEATURE_NO_TITLE);, this:

仍然停留在屏幕上,看来,它也被视为屏幕的一部分,因此"screenWidth"实际上大于可用部分.

still stays on the screen and it seems, it's also counted as a part of the screen so the "screenWidth" is actually bigger, than the usable part.

没有任何方法来获取可用部分而不是整个屏幕的大小吗?还是至少获得了滚动物体"的大小(但是会有一个问题,就是有些设备没有显示它们)?

Isn't there any method how to get the size of the usable part and not whole screen? Or at least get the sizes of the 'scrolling thing'(but there would be a problem, that there are devices that don't show them)?

推荐答案

我前一段时间有相同的问题,这是我找到的答案.显示活动维度.

I had the same question a while back and here is the answer that i found. Shows the activity dimensions.

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.graphics.Point;

public class MainActivity extends Activity
{
    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.main)

        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);

        int width = size.x;
        int height = size.y;

        //Set two textViews to display the width and height
        //ex: txtWidth.setText("X: " + width);
    }
}

这篇关于如何在Android中获取可用的屏幕宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆