-1

I'm currently working on a app that needs to display a listview of pictures and each picture must take up the entire screen.
I am currently getting the screen resolution and re-sizing the image.
The problem I'm having is with devices that use onscreen button.
how do I take into account the onscreen buttons or how can I find out how much space does the onscreen button take up?

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    height =metrics.heightPixels;
    width=metrics.widthPixels;
  • why do you use a listview for this? if each element must take up entire screen? can't you use something like imageview (which if configured correctly will scale your image for you) and register some kind of onTouch listener to "scroll" to the next picture? – Max Ch Jan 02 '14 at 19:16

3 Answers3

0

you can get the phone dimension with this and can adjust your button

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();  // deprecated
int height = display.getHeight();  // deprecated
Sunny
  • 219
  • 1
  • 10
0

You can find the height of the ActionBar (which is what I assume you mean by onscreen buttons) during runtime with the following code:

final TypedArray styledAttributes = getContext().getTheme().obtainStyledAttributes(
    new int[] { android.R.attr.actionBarSize });
mActionBarSize = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();

Then you can just add the ActionBar size to the screen dimensions.

A more detailed explanation can be found here: What is the size of ActionBar in pixels?

If you need the height of the screen with the onscreen buttons found on Nexus devices, you can use Display.getRealSize(Point).

Community
  • 1
  • 1
Kavan
  • 340
  • 2
  • 12
0

If you want the the display dimensions in pixels you can use getSize:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

If you're not in an Activity you can get the default Display via WINDOW_SERVICE:

 WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
 Display display = wm.getDefaultDisplay();

Before getSize was introduced (in API level 13), you could use the getWidth and getHeight methods that are now deprecated:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();  // deprecated
int height = display.getHeight();  // deprecated

For the use case you're describing however a margin/padding in the layout seems more appropriate.

Apk
  • 153
  • 1
  • 2
  • 18