Amir Dora.
Amir Dora.

Reputation: 2717

By what factor to increase width/height of icon for different screens - Android

I am developing an app and I am testing it on 420dpi device. However, I am keeping dimen.xml file and updating it roughly for different screen sizes. Since I don't know by what factor I should increase or decrease image on different screen sizes. I would like to know if there's any strategy or way to make it easier without having to test the app on different devices. Is there any cheatsheet?

for example, this is how I adjust the height for an icon. Obviously, I am just using rough estimates and find it hard to test (practically not possible) for every icon and font sizes.

dimen.xml

<dimen name="height_image_view_home" />

dimen.xml (w360dp)

<dimen name="height_image_view_home">50dp</dimen>

dimen.xml (w600dp)

<dimen name="height_image_view_home">90dp</dimen>

dimen.xml (w720dp)

<dimen name="height_image_view_home">150dp</dimen>

image icon

Upvotes: 0

Views: 95

Answers (1)

MRazaImtiaz
MRazaImtiaz

Reputation: 2187

I came across a library (in fact 2 libraries) that can help you achieve this without needing to create other layout resource files for other screen sizes — SDP and SSP libraries.

dependencies {
    implementation 'com.intuit.sdp:sdp-android:1.0.6' 
    implementation 'com.intuit.ssp:ssp-android:1.0.6'
}

In a situation where you are supposed to use a margin of 8dp, you can use @dimen/_8sdp instead.

For text size, you can use @dimen_/14ssp instead of 14sp.

the size will be changed according to the device sizes and resolution.

Learn more about these libraries

Upvotes: 1

Related Questions