Making Android XML Designs more responsive with Scalable DP & SP

Siddhant Khobragade
GDSC, IIIT Allahabad
3 min readNov 14, 2020
Android screen densities

“ There are three responses to a piece of design — yes, no and WOW! Wow is the one to aim for! ”

No need to get more exhausted over making lots of xml resources files with various qualifiers. Found a smart solution for it. 😎

i.e. SDP & SSP library/SDK.

Recently I was working on an Application whose designs were made to be compatible with every screen size. For doing so, I have to make lots of 🤯‘dimen.xml’ value resource files for each and every screen resolution as per the respective qualifiers.

For example, making an imageView’s width and height dimensionally compatible for a Tablet>600dp, I have to make a different dimen.xml resource value file with the qualifier ‘Smallest screen width’ and define all the dimen values correspondingly. Similarly, I have to repeat it for other resource qualifiers.

Various dimen resource files with different qualifiers.

Frankly speaking, it was okay for me to do it for the first or the second time. But after that, I felt that isn’t this a waste of time⏲ defining them each and every time I create a new project. The same could be happening with you too. So being frustrated😵, I googled over it and found🧐 a very cool and smart solution.

Just two lines/dependencies to add in your build.gradle file and you will get rid 🤓of those lots of resource files.

//Scalable DP and SP
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.intuit.ssp:ssp-android:1.0.6'

You can use it in a very similar way as you were using the dp and sp.

SDP(Scalable DP)

SDP library is helpful to define scalable size unit instead of just defining dp as unit. Example is

<ImageView
android:id="@+id/logo_img"
android:layout_width="@dimen/_48sdp"
android:layout_height="@dimen/_48sdp"
android:src="@drawable/woman_holding" />

This will make the size/dimension of your imageView automatically scalable to all screen sizes of different devices.

SSP(Scalable SP)

SSP library is helpful to define scalable size unit for defining text related dimens instead of just defining sp as unit. Example is

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title"
android:textColor="@color/black"
android:textSize="@dimen/_16ssp"/>

This will make the size of your text automatically scalable to the screen sizes of all the different devices.

Please refer to the below comparison between a non-responsive design and a responsive design(using scalable dp & sp).

The below xml design is created using hardcoded dimen values with formal dp and sp units for the Image dimensions and text size respectively.

Non-Responsive Design using formal sp and dp units.
activity_homescreen.xml

In the above xml code snippet I have used dimen values with scalable dp and sp units for the Image dimensions and text size respectively.

Responsive design using scalable dp and sp.

So, no more worries & anxiety regarding making of various dimen.xml files for each screen resolution qualifier. ✌

Make use of this smart solution in your own projects and save your time ⏲and energy🤓.

Happy Coding!!👩‍💻😄

References

--

--