Android picks wrong resource folder
I seem to have some problems with my resource folder - Android chooses t开发者_StackOverflow社区he wrong resource folder.
When in design mode, in the layout editor, I have the option to choose between different devices, to look at my design in different screen resolutions. I have specified three different devices, one for each resolution. The mdpi and hdpi shows the resources from the right folder, but when choosing my device with ldpi, it shows the resources from mdpi - which is wrong.
The settings for ldpi device is:
Small, Not Long, Portrait, Low Density, Finger, Soft, No Keys, Trackball, 320x240
When I run the program I get an InflateException , because it cannot find the right resources for my imageview in my layout: android:src="@drawable/psbgtop"
This is my res folder:
- res/drawable-hdpi/icon.png
- res/drawable-hdpi/psbgbottom.png
- res/drawable-hdpi/psbgtop.png
- res/drawable-ldpi/icon.png
- res/drawable-ldpi/psbgbottom.png
- res/drawable-ldpi/psbgtop.png
- res/drawable-mdpi/icon.png
- res/drawable-mdpi/psbgbottom.png
- res/drawable-mdpi/psbgtop.png
- res/layout/main.xml
- res/layout/settings.xml
- res/layout/settings2.xml
- res/layout/synchronize.xml
- res/values/strings.xml
- res/xml/preferences.xml
Can anyone figure out, why my folder structure seems to be wrong?
Best regards Frederik
You can use "aapt dump restable" to look at the actual resources in your .apk. There is no need to have a base resource when using density resources. There isn't enough information here to help much more than that, but my guess would be just that your code and resources are out of sync. Have you tried doing a full clean build?
It's a good idea to have a "base" folder (called "drawable" in your particular case) and put some "default" resources there so that Android has something to revert to, if it doesn't locate right resources. But in general it indeed looks strange, why none of dpi-specific resources were not picked.
I think the reason you get the runtime error is because you're testing/compiling it against Android SDK 1.5.
If you aim for 1.5 compatibility, you also need a default "drawable" folder, as of the official documentation, ldpi, mdpi, hdpi and nodpi modes were added with API Level 4 (Android 1.6).
http://developer.android.com/guide/topics/resources/providing-resources.html
ldpi: Low-density screens; approximately 120dpi.
mdpi: Medium-density (on traditional HVGA) screens; approximately 160dpi.
hdpi: High-density screens; approximately 240dpi.
nodpi: This can be used for bitmap resources that you do not want to be scaled to match the device density.
Added in API Level 4.
Edit:
If I'd be you, I'd simply rename the drawable-ldpi
folder into drawable
folder and store the ldpi files in drawable
精彩评论