如何在 Android 中获取可用的屏幕宽度和高度

2023-12-30

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:enter image description here

仍然保留在屏幕上,看起来它也被算作屏幕的一部分,因此“屏幕宽度”实际上比可用部分更大。

有没有什么方法可以获取可用部分的大小而不是整个屏幕的大小?或者至少得到“滚动的东西”的大小(但会有一个问题,有些设备不显示它们)?


不久前我也有同样的问题,这是我找到的答案。显示活动维度。

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);
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Android 中获取可用的屏幕宽度和高度 的相关文章

随机推荐