1

I am developping a game. I would like a picture to be shown on the screen. It should fill the screen's 90% in width (about 90%). I don't want the system to resize my images (I don't like the quality it results) I would like to put the pictures without rescaling / resizing.

<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/myPicture"/>

This is how I want it to look on different screens: enter image description here

In this case I have the resource image in 2 sizes (width: 720px for the first one, 1440px for the 2nd and 3rd). (The 3rd one is a tablet) I know if I would put them into different drawables folders, it would be good.
For the first one: drawables-mdpi
For the second one: drawables-xxdpi
For the third one: drawable-mdpi-xlarge

The only problem with this: My apk will be bigger than it could (the 2nd picture is duplicated, because the copy of it is in a different folder)

My question is: How can I make this work without duplicating, and easily maintaineable?

My google-ing's results: Don't use different drawable folders, I should use it like this:
/drawables/

  • myPicture_720.png
  • myPicture_1440.png

Then I can make different layout-s for every screen type, and the apk won't be much bigger. The problem with this is: it is too much work to maintaine

Easier way:
Use refs.xml
http://blog.vogella.com/2013/08/13/using-xml-layout-references-in-android/
/values-mdpi-xlarge/refs.xml

    <?xml version="1.0" encoding="utf-8"?>
<resources>
    <item type="drawable" name="myPicture">@drawable/myPicture_1440</item>
</resources>

(This is for the 3rd screen)

This way I can have only one layout, and good sized drawable resource will be used.

The only problem is:
I still have to maintaine a lot because of the names.
I use photoshop plug-in (Cut 'n' Slice Me), that exports the drawables in 4 different size in 4 different folders for the 4 basic densities.

I know this is not the regular way, how I should use the system, but please try to answear my question if you know some easier way.

I think it should work like this:
I could make 2 different folders, and I could make a reference for the whole folder to get drawable resources from that one. (In one folder the names will be the same (myPicture.png)

Note:
In my example 720px and 1440px was mentioned. In real dev it won't be the double, so the resizing can make it look worse.

TLDR:
If my drawables-xxdpi and drawables-mdpi-xlarge would be the same, how could I make the system to use the good resources without duplicating the folder?

Tomi
  • 3,370
  • 1
  • 16
  • 26
  • you can use linear layouts and weights to achive it...... – Lahiru Prasanna Dec 11 '14 at 10:40
  • You are right - but then the system RESIZE it. If I set weightsum=10. And the layout_weight=9 for my picture. Then if the original picture was not the 90% of the screen, the system will RESIZE it. (That is what I don't want). It is okay for me it is not exactly 90%, just about 90% - I know it will happen, because every screen is different size – Tomi Dec 11 '14 at 11:12
  • 1
    `I don't like the quality it results` When scaling **up** (you start from a small picture) the results are bad. When scaling **down** (you start from a big picture), the results are good. – Phantômaxx Dec 11 '14 at 11:19
  • Also in that case: would you just give a big resource size (for fullHD screens), or would you give for all densities. First case: The system has to scale down a lot. The second case: The tablet will use mdpi. Then it will "zoom into" the picture to fill all the 90% of the screen. (Because on mdpi it is just 720px) – Tomi Dec 11 '14 at 11:20
  • @Der Golem: Are you sure? it will be quite perfect in every case? – Tomi Dec 11 '14 at 11:22
  • One big resource for the bigger density. Android would automaticaly create the missing resource by scaling **down** that resource. – Phantômaxx Dec 11 '14 at 11:22
  • 2
    Maybe not **perfect in every case**. But acceptable, I guess. Better, though, if you could use a 9 patch. So, some areas will be stretched to fill and some others will be left unstretched, not to distort the meaningful parts of the picture. – Phantômaxx Dec 11 '14 at 11:23
  • Okay, I will try it, thank you (Unfortunatelly I can't use 9 patch in this case), I hope it will look okay – Tomi Dec 11 '14 at 11:27

0 Answers0