Skip to content Skip to sidebar Skip to footer

In Order To Make Your App's Ui Compatible With All The Devices Like Tablets,phones Or Watches Which Unit Is Preferred In Android?

I have used dp in my xml. but it's not giving me an accurate UI.

Solution 1:

For sure, dp is the most adequat unit to accomplish that goal. There in addition to that, you have to define several values folders where you define dimensions for scaling tablets or phones. E.g. define two values folders like:

values-largevalues-xlarge

Now define a dimen.xml file inside this folders, where you can put your measurements in (unit dp) for the corresponding screensize. Define a measurement like this:

<dimenname="value1">17dp</dimen>

Then embedd this sizes in your layout xml, like:

android:layout_height="@dimen/value1"

Depending on the screensize, the system will load the correct measurements from this folders, e.g. if you have a screen size large only the defined values in folder values-large will be loaded. For more information, also have a look at https://developer.android.com/distribute/essentials/quality/tablets.html

Solution 2:

dp is the preferred measurement size in Android.

For defining text size use sp, as it would preserve user font settings, for example, if user has set text as larger in its device settings, TextView with 12sp would show bigger text than TextView with 12dp text.

You can read more here: https://material.google.com/layout/units-measurements.html

Though not sure what you mean by "accurate UI" :)

Post a Comment for "In Order To Make Your App's Ui Compatible With All The Devices Like Tablets,phones Or Watches Which Unit Is Preferred In Android?"