Reputation: 1014
I had a multiple drawable directory because of different resolution like Drawable is for Mobile layout and Drawable-xxhdpi is for a Tablet layout. In Drawable-xxhdpi's XML file only dimension of drawable file is changed from Default Drawable directory (hight, weight, padding etc).
When i was build project it shows me Error of Duplicate resource because of same name of Drawable file in different different directory.
So tell me what should i have to do? where i have to put Tablet version's Drawable means Drawable-xxhdpi?
Or tell me if any other way for build Mobile and Tablet version both.
Error is:
[drawable-xxhdpi-v4/icon_loose] E:\Android Projects\Daily Backup\WMS\MarkTeqWms_12_03_2016\app\src\main\res\drawable\icon_loose.xml [drawable-xxhdpi-v4/icon_loose] E:\Android Projects\Daily Backup\WMS\MarkTeqWms_12_03_2016\app\src\main\res\drawable-xxhdpi\icon_loose.xml: Error: Duplicate resources
In picture i was showing that i have those directory and like a layout-xxhdpi i want to use Drawable-xxhdpi:
Upvotes: 0
Views: 700
Reputation: 125
sigh another poor soul inflicted with the confusion of the DPI buckets... Know that the density buckets (ldpi, mdpi, hdpi, etc) exist specifically for pixel dependent assets. Why? because there are a plethora of devices with potentially many different DENSITIES (density != size btw) and the fact is you can not know the exact DPI of the device that will run your layout. Thus, you'd need some way to ensure your graphics would look good on all screens.
Da da da DUNNN the density bucket was formed. Now in reality a device most likely will run at some weird DPI e.g. my phone is at 258DPI, and the android OS sees my device as a 258DPI phone. Not as a "hdpi" phone... In reality since we can never know the actual dpi of a device we can only assume it will exist in one of a few generalized states (ldpi, mdpi, etc) therefore, by designing our custom graphics according to those buckets we can ensure that any phone running our graphics will not display a pixelated version of our images.
Now the thing to remember is that the density buckets are nothing more than a duct tape solution to an overall problem. Let it be noted that the solution does in fact work, but it has only one use and that is for when we need to custom scale any asset that depends upon pixels. Though many people don't understand how the buckets work, and why they exist (Due to poor teachings on google behalf) and they assume that density is the end all be all solution to supporting many screens. (hence the reason you specified layout-xxhdpi). Though altering a layout based on density is never necessary because as mentioned earlier, to the android OS the phone is at the exact density it is at. Not any specific "bucket". Therefore it'll use a scale factor based on the literal DPI of the device. Thus ensuring that, for example, 25dp on any device will take up the same percentage of space regardless of the devices density.
The last thing to note is that while the DPI of the device is only useful for deciding the pixel sizes of our graphics, the screen SIZE (remember density is different from size) will make a huge difference. E.G. some devices will have 320dp worth of width, while others will have 480dp. Therefore alterting a layout is only necessary when you need to add/remove/change a layout based on the available space given.
Tl:DR Density buckets are a duct tape solution. Respect them but do not have faith that they are the solution to multiple screen support. Secondly, the DP unit can scale to any density device and take up the same relative percentage of space, and lastly when designing for multiple screens, we actually design for multiple SCREEN SIZES not density.
Upvotes: 1
Reputation: 5087
Android doesn't have a way for automatically deciding whether a device is a tablet or a phone. Putting a file inside drawable-xxhdpi doesn't mean that it will be rendered by tablets only. It only means that devices with a resolution that corresponds to that of xxhdpi will search for the resource in this folder. These devices theoretically can be anything that run Android (phones, tablets, TVs, watches).
To achieve what you want you have to define yourself what you consider a tablet. For example, if you think that any device with a width great than or equal to 600dp should be considered a tablet, then you should put the corresponding resources in resource folders with the qualification "sw600dp". Eg. drawable-sw600dp
, layout-sw600dp
, etc.
I would advice you to read more about this from Android's official doc Supporting Multiple Screens.
Upvotes: 0