javaandroiddimensionsandroid-screen-support

How to define width and height for an imageview for all screens?


I have an imageview with width 250dp and height 250dp, on a nexus 5 5.0 inch 1080x1920 xxhdpi is looks good, but when i change my emulator device to a bigger screen for example 6.0inch pixel 2 xl 1440x2880, 560 dpi it's really small.

I know i have to declare other dimensions in a dimens.xml file to support other screens and i'm using size qualifiers small, normal, large and xlarge but for some reason on some devices it doesn't look good.

What is the best way to define width/height for the imageview so it looks good on all screens?

Thanks


Solution

  • You should be having different density images (ldpi, mdpi, xhdpi, xxhdpi and xxxhdpi) or svg image to look good in different density screens. In order to look good in different screen sizes (physical size) - you must have check in your layout in different screen preview available in preview of xml design. For easy creation of the preview screen you will find orienation symbol in preview screen click it -> you will have drop down in that click Create Other -> next you will get a dialog in that you must follow the naming convention as in the documentation https://developer.android.com/training/multiscreen/screensizes. For example : for small screen you will have to name it as layout-small you will get activity_main.xml(small) in that you can change the image view properties to look good in that screen.