Issue
I'm currently tweaking my application to work with different devices. I ran into a problem with the old Nexus 7 (~216 ppi pixel density).
The problem is that it looks for drawables in tvdpi
, failing to find that it uses hdpi
assets. The assets that I want it to use are the xhdpi
or xxhdpi
drawables.
Is there a way for me to tell Android to use a specific folder for xhdpi
devices and sw600dp
devices (that have a dp value lower than xhdpi)?
I would prefer to avoid having to copy paste drawables.
Solution
What you can do is use 'references' to drawables in the dpi folders, so you don't have to copy assets around.
It can become quite tricky, but a quick explanation is:
Name your drwawables myDrawable-xhdpi or something like that, and put them in the xhdpi or no-dpi folder.
Then create the resource folders :
values-tvpdi values-xhpi
Inside of those folders create drawable.xml file, with an item for each drawable you want the nexus 7 to use (you will also need to create a drawable.xml in the values folder).
The items will look like:
@drawable/myDrawable-xhdpi
All layout files can just reference @drawable/myDrawable.
What we are doing is setting it up so that we can have only one drawable, but referencing that drawable from these drawable.xml files. When Android is asked to look for myDrawable on a tvpdi device, it will look in the drawable-tvdpi folder, which doesn't have a myDrawable, so it will then look in the drawable.xml file, and find a reference to the correct drawable to use.
Hope that makes sense.
Check out this article for more: http://android-developers.blogspot.co.uk/2011/07/new-tools-for-managing-screen-sizes.html
Answered By - athor
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.