verybadbug
verybadbug

Reputation: 929

Resolution trouble

I have a device with resolution 800*480. I create "Hello word" application. Then I get DisplayMetrics in onCreate of MainActivity.

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Log.d("Resolution", "resolution: " + metrics.widthPixels + " x " + metrics.heightPixels);

In DisplayMetrics there are 533*320 pixels. Why?

How can I make application for resolution 800*480 pixels.

Upvotes: 0

Views: 132

Answers (1)

Marcin Orlowski
Marcin Orlowski

Reputation: 75619

It's because you are reading device independent pixels not real pixels. These dip are equal to mdpi resolution. So despite real screen size, you should check what density it is (mdpi or hdpi or xdpi) and then put your hi-res assets in -hdpi suffixed folder (i.e. drawable-hdpi or layout-hdpi). Usually you set your layout in dp (so one layout XML file per activity usually suffices, and you should put them as usual in generic res/layout folder). and then put hi res drawables to make app look nicer on hdpi device

See this article for pixel-size and density relations...

Upvotes: 2

Related Questions