dimens.xml(w840dp) not working - android

This seems like a bug but maybe I'm doing something really silly and just can't see it. I have these value files:
The integer value files are behaving as expected. Inside the default integers.xml I have:
<integer name="card_item_columns">2</integer>
and for the integers.xml(w840dp) I have:
<integer name="card_item_columns">3</integer>
But when it comes to the dimens files, only the sw600dp one seems to do anything. For the dimens.xml(sw600dp) I have this:
<dimen name="card_width">264dp</dimen>
and for the dimens.xml(w840dp) I have this:
<dimen name="card_width">400dp</dimen>
If I use a Nexus 7 emulator device in portrait it shows 2 columns. When I rotate it I see 3 columns as expected. This proves that it's at least 840dp wide as that integers.xml(w840dp) file is the only place it can get 3 columns from.
However if it's w840dp why doesn't it use the card width value in the dimens.xml(w840dp)? Is this not possible? Can a "w" qualifier not override an "sw" qualifier? I think it should.
I can adjust the value in the sw600dp file and the change is reflected, showing that it's getting called correctly from the layout file.
What basic concept am I not getting here? I find it hard to believe that there is a bug here. Surely if there was, other people would have noticed it. Spot the silly error to get some points. Or give me a clue that leads to the solution. Thanks.

The documentation on the Android site regarding resource qualifier precedence is pretty comprehensive:
Providing Alternate Resources
All other things being equal, smallestWidth has higher precedence than Available width
Configuration | Qualifier value
smallestWidth | sw<N>dp
Available width | w<N>dp

Related

Ccorect values folder not getting selected in Android Studio

I thought I had this device density/size thing down, but apparently that is not the case. I have created a new hardware definition within Android Studio using the following dimensions and size.
9.7"
768 x 1024
This results in an ldpi device, which is what I am after. This was mirrored off of the HP Touchpad device.
I am using several dimens files within my application which are contained within their associated values folder with 2 resource qualifiers each. A typical values folder in my app looks like this.
values-sw320dp-xhdpi
Using the information above, I believe this should result in the system looking for the dimens file in my values folder shown below.
values-sw480dp-ldpi
I arrived at this conclusion by taking the pixel dimensions of 768 x 1024 and multiplying them by .75 which would result in a with and height in dp of 576 x 768. Since the smallest width is 576, this should use the values folder referenced above of values-sw480dp-ldpi.
I know that it is not using the values specified in this dimens file because the value shown in the layout is from one of my other values folder/dimens files. Additionally, it is not actually using the values from the file that the layout is referencing either, as changes to that dimens file have no impact on the layout. It simply is stopping on the first one seen (or something) but not actually using the value. I have encountered this situation many times and the issue is always fixed by getting the "correct" values folder defined with the appropriate resource qualifiers. The issue here is that I don't know what the system is actually trying to use and it clearly is not coming up with the same calculations I am.
Here is a screen shot of the device I have build in Android Studio.
Android supports combination of qualifiers in defined order of priority. Here in Table 2. you can see this list.
And here you have fine description of how Android finds the best-matching resources.
Also, I wonder what is the reason you create values folders with Screen pixel density (dpi) qualifiers. I could be wrong, but I think that density matters only with drawables/mipmaps etc.

Can't figure out which dimens.xml used by different devices

I'm using different dimens.xml to allow my app to support different screen resolution.
The problem is that it looks like dimension are missing for Nexus S and Nexus One and it also looks like if Nexus 7 (both version) and Nexus 9 are sharing the same dimens.xml file.
Here's the list of my dimens.xml files (if there're some "useless" file please tell me, I will remove them).
Dimens.xml files pic
Here's another pic showing you the result on different screen res.
Results on different resolutions
Thank you so much for your help
Why aren't you using the identifier sw (smallest width). I think that will be much easier to maintain.
Edit:
Just change w600 to sw600. This way only screens with minimum width of 600 dp will use those dimensions. check this link stackoverflow.com/a/32685049/4567228

Combining Screen Size and Density Value Files

Something is really wrong with Android.
I have one Device with a "Normal screen and MDPI" (LG Optimus 2X P990)
I have one Device with a "Normal scren and XHDPI" (Samsung Galaxy S3)
I try to have all layouts in one single folder, for all views. If I change the color/text/whatever on one view, it goes globally. To have that value such as a "Color" to be located in all different layout means I have to change all the files when changing something so rudimentary as a color, or textsize.
Then in each "values-normal, values-xhdpi, values-large" I have set all settings unique to that device.
Example "values-normal"
<dimen name="text_small">10sp</dimen>
Example "values-xhdpi":
<dimen name="text_small">4sp</dimen>
Example "values":
<dimen name="view_textview_title">#dimen/text_small</dimen>
Currently, the MDPI device doesn't load the values from the "Values" folder, only when added to "values-normal" and the XHDPI device doesn't load the "values-xhdpi" if there is a Normal folder.
Well, to say the least I can't optimize the App for two different devices. That's what wrong.
Cause, I read that the "Normal" folder overrides the "XHDPI" folder for a Normal screen device with XHDPI Density. But to be able to see the Title text I have to set the text on the XHDPI text size to something like "4sp" while on the Normal with MDPI it's about "10sp".
A higher density will multiply the value more, a lower - less. Am I right? Then this way there is no possible way to optimize an App for two different devices with just a Density change. Each screen size with it's density size needs it's text size.
So, my question is the following...
Can I combine "values-xhdpi-normal" "values-mdpi-normal", "values-hdpi-normal" and such?
Otherwise, I have to make the App ugly for some devices and look good on some. I like probably more like me, don't use "TextSize = 10" on the whole page. A title is a title, larger, a menu is a menu, smaller text, descriptions on a menu even smaller. There you go.
Reason I'm asking is because I don't wanna reset the current layout without it being possible, too much work for nothing otherwise and Eclipse is buggy enough with it's productive approach of having to add a single line just to force a reinstall when a library has changed or restart the whole environment for it to understand that something's changed - especially with Values!

Values in /values-normal-mdpi overriding values in /values

I'm a little confused, hopefully somebody can clarify for me.
I have a dimens file in /res/values, but I want to override some of those default dimens for normal-mdpi screens. i.e. I want to have special dimens for normal-mdpi that won't affect the rest of my screen size / density buckets.
However, the dimens I put in res/values-normal-mdpi/dimens.xml are affecting other screen sizes / resolution buckets (e.g. large-xhdpi). I would expect large-xhdpi to still pull from res/values and not be affected by what I put in rev/values-normal-mdpi.
Does anyone why? And how I can achieve the desired effect?
This SO Question is very similar, and the answers to it very helpful (1) (2). Basically, the Android system will find the best match using these methods. For screen density, it will find the closest match and take that. It will only use res/values/dimens.xml if the dimension isn't in any of the density-specific directories.
In this case, create another version of dimens in any directory that will be a "better match" for the other devices that you want to support (ex: values-hdpi), and put the default values of the dimens that were overriden in there.

Activity not picking up the correct orientation

For my App, I need to fix the orientation to portrait on Phones and allow portrait and landscape on Tablets. I have looked at answers here and but I want to try to do the same using xml alone.
I tried adding the following line in my manifest
<activity
android:theme="#style/Theme.ActionBarLargeTitle"
android:name="com.work.activities.MyActivity"
android:screenOrientation="#integer/orientation_supported"
android:exported = "false"/>
In res/values/dimens.xml I added the following line (1 corresponds to portrait)
<integer name="orientation_supported">1</integer>
I have created another file, res/values-sw600dp/dimens.xml in which I have added (-1 corresponds to unspecified)
<integer name="orientation_supported">-1</integer>
On phone this code works fine and the Activity is always in portrait mode. On Nexus 10" Tablet(width 800dp) this fails and it is fixed in portrait mode. Is there anything wrong with this approach?
EDIT:
I have checked with various values and in all cases(in all devices) the value from res/values/dimens.xml is picked up. If this value is missing there is an error when the app is installed 'Installation error: INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION'.
The issue is you are using -sw600dp qualifier, which doesn't actually check orientation but rather checks that the shortest side is at least 600dp. Try using -land or -port qualifiers instead.
There are two possible problems here:
Make sure your tablet is reading from -sw600dp folder. I know it may sound weird for 800dp device. The easy way to check is to add a string with the same key in both folders and display in TextView.
Make sure your tablet understands -1 value. The phone I checked with did. Try changing to 0 and see if it forces landscape.

Categories

Resources