Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is dimens.xml(w820dp) in android studio.?

Upon creating the new project in android studio in the following path were created two xml files by default.

..res/values/dimens.xml
..res/values/dimens.xml(w820dp)

Am aware of the file dimens.xml where we can define the dimensions for the elements, but why the second file dimens.xml(w820dp) created by default.

Can someone please shed lights on why it is needed and when we can use it.

like image 968
Raju Avatar asked Feb 07 '23 11:02

Raju


2 Answers

You can define several folders for each desired screensize in Andorid Studio. In your case, android studio defines values folders where you define dimensions (measurements) for scaling tablets or phones. E.g. it defines two values folders like:

values-large
values-xlarge

or in your case

values-w820dp

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

<dimen name="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

EDIT1: So basically if you see the file dimen.xml(w820dp), the values in there are only used, if the app is executed on displays with 820dp and above, in this case, it means tablets.

like image 117
Thomas Richter Avatar answered Feb 09 '23 02:02

Thomas Richter


In fact you have not file named ..res/values/dimens.xml(w820dp) at all in your project structure (check yourself). What you have instead is ..res/values-w820dp/dimens.xml file but to make editing right file easier, Android studio will (in Android view) show it as such. This file will be used by the framework on devices with display width 820dp or higher:

Specifies a minimum available screen width, in dp units at which the resource should be used—defined by the value. This configuration value will change when the orientation changes between landscape and portrait to match the current actual width.

On other, "plain" dimens.xml will be loaded. See Providing Alternative Resources documentation on resource qualifiers to find out more about possible options and benefits.

like image 41
Marcin Orlowski Avatar answered Feb 09 '23 02:02

Marcin Orlowski