欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android 获取物理屏幕宽和高

程序员文章站 2022-07-14 17:30:09
...
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        DisplayMetrics metrics = new DisplayMetrics();
        Display display = MainActivity.this.getWindowManager().getDefaultDisplay();
        display.getRealMetrics(metrics);
        int width = metrics.widthPixels;
        int height = metrics.heightPixels;
        Log.e("-------width", String.valueOf(width));
        Log.e("-------height", String.valueOf(height));
    }
}