-3

First of all, Thanks for giving Negative Votes in the first place. (i expect at least 10 negative votes to be honest by the honorable so-called "experts"(excluding those who believe even a simplest and smallest problem can cause a huge difference)).

So coming to my Question.

It's a very casual question that I am implementing a navigation drawer with a header image of 576x324(ratio as 16:9).

According to the Guidelines, the total width(in dp) of the drawer should be

for a device like 720x1280px screen and xhdpi

width in dp = (720x160)/320 - 56(toolbar size)=> 304dp

height in dp = 304 * (9/16) = 171dp

but the device like google nexus 4, 768x1280px with the same xhdpi

width in dp = (768x160)/320 - 56(toolbar size)=> 328dp

height in dp = 304 * (9/16) = 184dp

So, for the same xhdpi, I am getting two different widths and heights.

How can I manage this simple bug in android to make a common size in dimens.xml file?

Rahul Chokshi
  • 670
  • 4
  • 18
rituparna
  • 91
  • 1
  • 12

2 Answers2

0

Get the Screen width ( int width = Resources.getSystem().getDisplayMetrics().widthPixels)

Do the calculation by using this width.

Wasir
  • 185
  • 2
  • 11
0

Rather than calculating the width of drawer. What you can do is prepare the dimens file for different screen size. For example for landscape and portrait. For handling different layouts.

Store the width in the dimens and accordingly Android will fetch the suitable size.

<!-- Per the design guidelines, navigation drawers should be between 240dp and 320dp:
     https://developer.android.com/design/patterns/navigation-drawer.html -->
<dimen name="navigation_drawer_width">240dp</dimen>

For more information on screen sizes: Handling Screen Sizes

Hope it helps.

Mohammed Rampurawala
  • 3,033
  • 2
  • 22
  • 32
  • yes i already have my layouts as sw,320dp,sw480dp,sw600dp,and sw720dp. but both devices have different resolution but same density. and calculating the width for different resolution with same density is confusing me – rituparna Sep 03 '18 at 06:28
  • Rather than making common size. Give sizes according to the device width and you can use the dimens values for different layouts. – Mohammed Rampurawala Sep 03 '18 at 06:39