Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a device's maximal width and height in android

Tags:

android

view

Hi I have a problem creating a custom view for an Android application. My custom view wants to use if permitted the maximum screen width. I couldn't find any way to retrieve this value.

Can anybody point me to the right method?

like image 647
sulf Avatar asked Sep 16 '09 03:09

sulf


1 Answers

Try

mWinMgr = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
int displayWidth = mWinMgr.getDefaultDisplay().getWidth();

where context is Context instance.

By default, the FrameLayout in which your layout is kept, fills the whole display horizontally (vertically you can have status bar). So you can set the maximum possible width by using android:layout_width="fill_parent" correctly.

like image 94
Dimitar Dimitrov Avatar answered Oct 13 '22 08:10

Dimitar Dimitrov