Naveen
Naveen

Reputation: 1060

Showing pictures in Android app - Resolution?

I've a Photo gallery in my app. The set of pictures are stored in the drawable folder. I'm making use of ViewPager when the user swipes through the images.. What is the width and height in pixels and dps for xhdpi, hdpi, mdpi??

I know that the Android documentation says px = dp*dpi/160.. but I'm still confused about what should be the pictures download pixels so that it fits in all screen sizes??

Upvotes: 0

Views: 198

Answers (2)

Chintan Rathod
Chintan Rathod

Reputation: 26034

Use following function which give you height and width of current display

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
deviceHeightPix = displaymetrics.heightPixels;
deviceWidthPix = displaymetrics.widthPixels;

based on this, you can pass data on server to fetch relative images.

Upvotes: 0

Jim Baca
Jim Baca

Reputation: 6132

There isn't one magic size that guarantees that it fits all screens perfectly. There are more than one screen size that fall under each density.

You should look at making your layout scale well on as many devices as possible. In your case it sounds like you shouldn't be focusing on an a specific pixel size, but rather how to display correctly on the common screens and gracefully display on less common ones. That being said I would do the following:

I'd look at the dashboard here. I'd make layouts targeting first targeting hdpi with a normal screen size(50.1% of the market) followed by xhdpi(25.1%) with a normal screen size, followed by mdpi(11%) normal screen size. Check table 3 on this page for common screen sizes for those values. Since you will be most likely using an image view make sure to check out the scale type attribute to help handle when the image view isn't at

As a side note(maybe useful later)if you are having difficulties translating sizes between densities and raw pixel values use this calculator.

Upvotes: 1

Related Questions