Pregunta

I built an Android tablet application and I'm trying to figure out how to make the system select the correct resources.

I understand the concepts described in the documentation. There are a number of different resource folders for different densities ldpi, mdpi, hdpi, etc... - but is there a way to have the system select resources based on resolution of the device? In the layout folder structure you can specify minimum width with layout-sw600dp. Is there a similar mechanism for resources? There are several devices considered medium density that have different resolutions. Ideally I would like to define resources for resolutions and have more flexibility than just pixel density.

I've also tried to use the built in scaling but it doesn't appear to work with my Nexus 7. Resources that are designed for higher resolutions do not seem to scale down at all. Perhaps I'm doing something wrong.

Thanks.

¿Fue útil?

Solución

I'm not 100% sure I read your question correctly, but you can suffix any subfolder of the res/ folder with the target specifiers. So not just res/layout-sw600dp, but also res/drawable-sw600dp and res/values-sw600dp. These rules can be combined, so res/values-sw600dp-mdpi will also work.

Also note that the Android SDK Documentation is a bit flaky in this area. The Training section explains a neat trick using resource aliases that helps you avoid copy-pasting layout XML's, but the API Guide and Reference docs never mention it, so it's easily overlooked.

Otros consejos

you can, you can specialize folder name like this, drawable-800x480, but make sure that greater value will become first(800 in this case)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top