When supporting different screen sizes (densities) in Android often the focus is on creating different layouts for every possible screen. I.E.
Although making a different layout for different screen sizes is theoretically a good idea, it can get very difficult to accommodate for all screen dimensions, and pixel densities. Having over 20+ different dimens.xml
files as suggested in the above answers, is not easy to manage at all.
How To Use:
To use sdp
:
implementation 'com.intuit.sdp:sdp-android:1.0.5'
in your build.gradle
,Replace any dp
value such as 50dp
with a @dimen/50_sdp
like so:
How It Works:
sdp
scales with the screen size because it is essentially a huge list of different dimens.xml
for every possible dp
value.
See It In Action:
Here it is on three devices with widely differing screen dimensions, and densities:
Note that the sdp
size unit calculation includes some approximation due to some performance and usability constraints.