Get the screen size in Android

Android screen size is different for different phone models.

There are some screen resolutions already defined in Android.

They are:

  • QVGA (240×320, low density, small screen)
  • WQVGA (240×400, low density, normal screen)
  • FWQVGA (240×432, low density, normal screen)
  • HVGA (320×480, medium density, normal screen)
  • WVGA800 (480×800, high density, normal screen)
  • WVGA854 (480×854 high density, normal screen)

Now let’s see how to get the screen size,

01@Override
02public void onCreate(Bundle savedInstanceState) {
03super.onCreate(savedInstanceState);
04setContentView(R.layout.main);
05int ht;
06int wt;
07DisplayMetrics displaymetrics = new DisplayMetrics();
08getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
09ht = displaymetrics.heightPixels;
10wt = displaymetrics.widthPixels;
11}
Here, ht will return the height & wt will return the width.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值