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));
}
}