I’m having a hard time trying to figure out how (and if) Android guidelines can be helpful for what I want to get.
My aim is to design a layout showing an image atop a texview filled with lines of text.
Both have to match the width of their parent container.
The problem is that the width of the imageview depends on the width of the screen that I can’t know in advance.
On the Android documentation the concept of dip is central, but after all, it is just a way to make the real size of the image the same for every situation, it has nothing to do with the screen size.
How can I proceed?
1) putting in the res folder an image large enough to be resized (i.e. shrunk). Hoping that this doesn’t create artifacts or doesn’t require some resource
2) some variant of 1. with images in different folders
3) creating an image (and if maybe saving it somewhere) for each screen size and rotation, the first time it is necessary
4) other solutions
Your help will be helpful not only to optimize this layout, but also to let me understand the rationale behind designing layout based on dip, that in many situation I can’t understand.
Your are right that "every screen is different." Putting images in each res
folder will only handle the general cases of screen density - not actual screen size.
Having a folder that contains all possible image sizes would likely get very large (not for all images, but for high quality complex images).
You should have 1 image that will satisfy the desired image quality for all screen sizes (maybe even scale-up for xxxdpi, for example, but satisfactorily). Then use screen size calculations and BitmapFactory
scaling to adjust. You will also need to manage memory properly, especially on older, smaller devices.
EDIT:
Android has a wide variety of resources to help you manage IP, image assets, graphics, etc. If you have a large team, hundreds of image assets and have common use-cases (buttons, spinners, icons, etc.) for the thousands of devices that exist then using resource folders help keep things organized for your team. If you produce games and are constantly creating, displaying and resizing image assets, then the resource folder solution may not be ideal or may result in a bloated APK. Additionally, for different density screens you may want to use different resources/graphic files but not write tons of code to manage that, so Android provides built-in tools to help.
Note that Android addresses a very long list of Drawable
types (http://developer.android.com/guide/topics/resources/drawable-resource.html) for the wide variety of app graphic needs - animations, mipmap, 9-patch...
In your case, you are asking about a single image that you want displayed in a particular manner. You are welcome to use resource folders (since they are available) to accomplish this goal, but since you sound like a small team with a need to display a single image in a specific way, you may be better off simply providing a single image, asking the screen for its size and displaying it. The phone recalculates and redisplays the same images from the resource files Android provides on a regular basis, too. You are not really "saving" time, CPU cycles or much of anything by using them for a single image.