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

4

5

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.

Avestan answered 28/7, 2016 at 11:44 Comment(1)
developer.android.com/guide/topics/resources/…Schug
A
7

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.

Anaclinal answered 28/7, 2016 at 11:47 Comment(0)
D
1

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.

Downcome answered 28/7, 2016 at 11:57 Comment(0)
B
0

Main use case of these files is to Support variety screen resolutions for user interface

dimens.xml

Android automatically take values from this file for device with dpi less than 820dp

dimens.xml(w820dp)

Android automatically take values from this file for device with dpi greater than 820dp

How to use

Declare dimension in these files with same name(dimens.xml)

<dimen name="button_width">200dp</dimen>
<dimen name="button_height">40dp</dimen> 

Change only in their values (dimens.xml(w820dp))

<dimen name="button_width">400dp</dimen>
<dimen name="button_height">80dp</dimen> 

w820dp

 for screens with more than 820dp of available width. This would include 7"
 and 10" devices in landscape (~960dp and ~1280dp respectively)
Bursiform answered 28/7, 2016 at 12:22 Comment(1)
what happens if the dpi is exactly 820Disadvantageous
G
0

w820dp is a qualifier value to provide alternate values for different dimensions. This is used to localize to device types properly.

Gillman answered 28/7, 2016 at 15:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.