Android Studio 0.8.6 multiple values folder - android

I am using multiple values folders like values-hdpi ,values-xhdpi , values-xxhdpi folders to support multiple screen sizes. Lets say I have a dimension named "listitemheight" in all that values folders with different density pixel values.My question is, when I select between Nexus S(hdpi) and Nexus 5 (xxhdpi) Design rendering of Android Studio IDE does not pick specific dimension for the screen size .Is there any way to do that correctly ?
In values-hdpi
<dimen name="listitemheight">30dp</dimen>
In values-xxhdpi
<dimen name="listitemheight">70dp</dimen>
EDIT : It always chooses hdpi folder

Try using folders with names like "values-w600dp" . I had the same problem with you and this was the solution for me.
Starting with API Level 13 (Android 3.2), the screen sizes are deprecated in favor of using the swdp qualifier. This new qualifier declares the amount of space a given layout needs. It is strongly recommended that applications that are meant to run on Android 3.2 or higher should be using these newer qualifiers.
For example, if a layout required a minimum 700dp of screen width, the alternate layout would go in a folder layout-sw700dp
Source : http://developer.xamarin.com/guides/android/application_fundamentals/resources_in_android/part_4_-_creating_resources_for_varying_screens/

Related

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.
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.
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.
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)
w820dp is a qualifier value to provide alternate values for different dimensions. This is used to localize to device types properly.

Android : Screen Size

I'm working on android application and got in trouble of multiple screen support. I developed the app for 1080x1920 and when i tested the app on my friends Micromax Unite 2 with resolution of 480x800, it was something else. So i made two folders in the layout as:
layout-1080x1920
layout-480x800
thinking that the 480x800 device will pick up the layout-480x800 folder. But no it used the layout-1080x1920. So what should i do? So that the device having resolution of 480x800 works on layout-480x800
I suggest naming the folders as such:
layout-sw600dp
Where sw600dp means Screen Width 600dp. This layout folder will be used by devices with screen widths of 600dp or more (typically all 7-10 inch tablets, or just very dense screen). And when you are targeting for the phone use just the layout folder without any specified criteria. All phones not matching the sw600dp will use the default layout resources. Possibly also consider using
layout-sw600dp-port
if you need to use specific layouts for portrait orientation, likewise you can do
layout-sw600dp-land
if you wanted to specified layouts for landscape.
The link cricket_007 provided is where I learned this information
Note that 1080x1920 equates to about 540 x 960 dp in dp measurement, which is why I suggested to use the particular 600dp for width
giving the folder names pixel according to android screen support dev page. Even if you know all possible resolutions for every device, the android system takes those *xml files/drawables etc specified by their DPI, not PX. Those dpi resolutions still can change on runtime, such as, when your activity uses a tool bar (which is not part of your dpi resolution). Name your folders layout-xlarge, layout-large, layout-normal, layout-small for *xml layouts. I suggest to put 4 different xml files with same name in each of them and try it again for different devices.

Android multiple screensize support

I need some suggestion with supporting multiple screen size,
Which will work
using
this
values
values-hdpi
values-large
values-ldpi
values-mdpi
values-small
values-xhdpi
values-xlarge
or
this
values-sw360dp
values-sw600dp-land
values-sw600dp-v21
values-sw720dp-land
values-sw720dp
values-v17
values-v21
values-2400dp
values-w720dp-land
values-w720dp
what values folders should i create in the res?i want to know all of it, if i may
Do i need to programmaticly declare or just put #dimens/something in the layout xml?
3.DO i need to make more layout folders to support multi screen size or just one layout folder and using #dimens is enough to handle multi screen size?
First and foremost, the following are depreciated from Android 3.2 (API 13) and up...
values
values-hdpi
values-large
values-ldpi
values-mdpi
values-small
values-xhdpi
values-xlarge
Basically, you only need to use these when you are developing for devices running anything lower than Android 3.2 (API 13).
Smallest Width
values-sw360dp
values-sw600dp
values-sw600dp-land
values-sw600dp-v21
values-sw720dp-land
values-sw720dp
The "sw" means Smallest Width. The OS will pick the one that fits the smallest available width that is available to your activity window. Therefore, if you have a device that is 700dp wide, it will use the resources from values-sw600dp for portrait and values-sw600dp-land for landscape because 600dp is the "smallest width" that you have defined and 720dp. If you wanted, for example, drawables that are used on screens 1024dp or wider then you would create a directory called values-sw1024dp. The naming scheme is as follows: [resourcetype]-swdp-optionalFlag
Note: That optional flag tells the OS to only use resources for that specific instance. For example, the flag "-v21" means that it should only use those resources if the OS is API level 21 or greater.
Available Screen Width
values-w720dp-land
values-w720dp
These specify the minimum available width at which the resources should be used.
The Android docs describe it way better than I can...
This is often useful to determine whether to use a multi-pane layout,
because even on a tablet device, you often won't want the same
multi-pane layout for portrait orientation as you do for landscape.
Thus, you can use this to specify the minimum width required for the
layout, instead of using both the screen size and orientation
qualifiers together.
Supporting Multiple Screens
Question 2 & 3
Do i need to programmaticly declare or just put #dimens/something in
the layout xml?
You only need to put the above directories in your /res directory.
So, for example, your layout directories... you would put something like this in your /res directory:
layout
layout-land
layout-v14
layout-land-v14
layout-sw600-land
layout-sw600dp-land
and for your drawables you might have something like (for pre-3.2 support):
drawable
drawable-hdpi
drawable-hdpi-v11
drawable-mdpi
drawable-ldpi
and for your values:
values
values-v14
values-sw600dp
values-sw600dp-land
values-w820dp
values-w820dp-land
The both can work.
To support multiple screen size, the most common one used in res/value is dimens.xml. (the name of the file is just convention)
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
In other res/value-XXX, the value of activity_horizontal_margin in dimens.xml can be other to fit your need.

Multi screen in Android

i used specifies pixel size for several screen size in Android.
For EX : layout-800x480 or drawable-800x480.
We have two sizes of 5.1 inches, a 4-inch for 480x800. How to make a folder and say which one I need? I want both.
You need to create the folder layout-800x480 and if you want pictures this resolution specifies you have to create the folder drawable-800x480 or you can use the default folder hdpi, xhdpi, etc...
More info Android Developers

Android apply styles for different screens

I have an application, that need to run in 2 different devices:
600x1024 & 480x800.
For these devices, I want to apply different styles (they has different ratio).
How I can do it, as both of them has hdpi?, e.g. values-hdpi, values-mdpi have no effect....
P.S. Android 2.2.
Take a look at the available resource directory qualifiers. There are also screen size qualifiers you can use.
In your case you need the large and xlarge qualifiers. Try that.

Categories

Resources