开发者

Device width for an android phone in landscape mode?

开发者 https://www.devze.com 2023-03-20 20:26 出处:网络
I\'m looking to adjust my page width when an android user rotates their phone to landscape. Problem is, I don\'t know what the device width开发者_开发技巧 is to set an exact pixel amount for my contai

I'm looking to adjust my page width when an android user rotates their phone to landscape. Problem is, I don't know what the device width开发者_开发技巧 is to set an exact pixel amount for my container div. I guess at 640, but it doesn't seem right. Does anyone know, offhand, what the device width for a landscape-oriented android device is? Or does that vary from device to device?

Thanks!


You shouldn't be guessing for an exact pixel width. I will just use dip (instead of px) on some of the glue pieces (like padding or the sides) and just let the main application expand naturally to fill it up.


It varies from device to device. You have to make generic ways to draw the screens. If you're setting xml layouts, then you can set widths and heights using the various notations.

What is the difference between "px", "dp", "dip" and "sp" on Android?

If you're setting the size dynamically at runtime, then screen size can be obtained through the "Display" class.

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Log.d(TAG, "Height = " + display.getHeight() + " Width = " + display.getWidth());

The width and height will be adjusted depending on your orientation of the phone.

The information is generally given to you through the onDraw methods through the Canvas object. You can use canvas.getWidth() to get the width of the screen and canvas.getHeight() to get the height of the screen.

0

精彩评论

暂无评论...
验证码 换一张
取 消