Reputation: 1724
I have a ImageView which is 450px*450px,it show perfectly on Note 3(1080*1920), but when I run the app on other smaller resolution device, the ImageView shown larger, and some other contents doesn't fit in the screen. Any solution to solve this kind of problem? is it about the unit(px, dp)?
Upvotes: 0
Views: 436
Reputation: 272
Your Screen Resolution Represents that you are Setting the ImagevIew height and width for xxhdpi resolution device and the Second thing use dp for density pixel it cover the screen according to resolution use 150dpX150dp for ImageView use the following link for px to dp conversion http://pixplicity.com/dp-px-converter/
Upvotes: 0
Reputation: 11873
The reason is every devices has different screen dimensions, so either you have to re-size the ImageView based on the screen size or simply use different size Images for your ImageView which will be used automatically based on the screen dimension. To do so, check this,
A. Getting the screen dimension programmatically and settings the appropriate size into the ImageView,
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics ();
display.getMetrics(outMetrics);
float density = getResources().getDisplayMetrics().density;
float dpHeight = outMetrics.heightPixels / density;
float dpWidth = outMetrics.widthPixels / density;
B. Adding different image sizes for different screens,
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
The following code in the Manifest supports all dpis.
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
Upvotes: 1