Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 12    Views: 69

Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
07/09/13 07:59 AM (12 years ago)

Android image / Density Q's :)

Hi all, On the Android road, I've just been reading about screen sizes and densities, etc. My question is, how do you set the project up to read the correct density of the same image? Also, is it just the image size that determines its density? Many thanks.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
07/09/13 02:30 PM (12 years ago)
http://developer.android.com/guide/practices/screens_support.html It's the density that determines the density. Remember, 'screen density' is really just resolution vs display size. 72 dpi is always 72 dpi. However, if I have a 200 pixel by 200 pixel image that is 72 dpi, and I squeeze it into a 100 x 100 space, I've effectively doubled my density. Cheers! -- Smug
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
07/09/13 02:36 PM (12 years ago)
Yup, been reading these Smug! However, your explaination is exactly what I was after, thanks! How do you add the same image with different size and density to your project? All the best.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
07/09/13 04:05 PM (12 years ago)
Basically double up. Or triple up (or down) as needed. It's the same concept as iPhone 3GS and iPhone 4+ with Retina. a 40 x 40 pixel icon at 72 dpi for an iPhone 3GS should be a 80 x 80 pixel icon for an iPhone 4+ similarly, a 40 x 40 pixel icon @ 72 dpi for an mdpi device should get an 80 x 80 pixel icon for an hdpi device, a 20 x 20 for ldpi, 160 x 160 for xhdpi.... although I basically design for mdpi and hdpi... Cheers! -- Smug Just as a side note, if you're 'really' going to develop for 'all' densities, I've found it better to start low and go high, versus high to low. It's easier for me to take a small icon, enlarge it, and 'fill in the blanks' than it is to take a high resolution image, shrink it, and make all that detail fit in a smaller space.
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
07/09/13 04:24 PM (12 years ago)
Ah cool cheers. What I was getting at is how you name the images, ie for ios you use @2x? Do you call it by the same name and plonk them all in the res draw location? Thanks again :)
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
07/09/13 05:46 PM (12 years ago)
Oh. for android, I make segregated images. I name them 'similar' to iOS, but no "@" or any odd characters. I usually put a set of 'mdpi' in res/drawable and I put specific resolutions (all named 'image.png' or whatever) in res/drawable-mdpi, res/drawable-hdpi, etcetera... The device will select the correct resolution from the correct directory, and if not present, will fall back to 'res/drawable' for the rest... Cheers! -- Smug
 
theMonster
Code is Art
Profile
Posts: 435
Reg: Oct 18, 2011
US
8,050
like
07/09/13 08:57 PM (12 years ago)
Well remember that the @ sign in Objective-C just means that it's an Objective-C object. Since Java doesn't have that. -tM
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
07/09/13 10:15 PM (12 years ago)
Brilliant Smug, just what I needed. Thank you.
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
07/09/13 10:28 PM (12 years ago)
Just to be clear, if you develop for mdpi and hdpi do you develop all screen sizes for these? EG - mdpi small screen 320x480, large 480x800, xl 1280x800. If you develop for all screen sizes in mdpi how would you name the images?! Thus, image.png in res/drawable-mdpi and image.png in res/drawable-hdpi makes sense. How are these distinguished in the same directory for different screen sizes?! Thanks greatly!
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
07/09/13 10:35 PM (12 years ago)
you name the images the same. You just put them in different places. the basic dir structure is: --res/drawable |_ image.png --res/drawable-ldpi |_ image.png --res/drawable-mdpi |_ image.png --res/drawable-hdpi |_ image.png --res/drawable-xhdpi |_ image.png what happens is the device will choose the correct directory for resources. If available, it will take them from the 'resolution appropriate' directory (res/drawable-mdpi, for example) and if it cannot locate the 'image.png' resource in the 'res/drawable-mdpi' directory, it will then look in the 'res/drawable' directory and use that resource (if available). So, in your code, or in your layout file, you still use 'image.png' and let the device figure out 'which' image.png is correct for it. Similar to xcode, you don't actually 'use' [email protected], you let the system figure out if it needs it or not. If it does, it uses it. If not, it doesn't. If it needs it, and can't find it, it falls back to image.png. (about the) same thing happens in android. Cheers! -- Smug
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
07/09/13 10:43 PM (12 years ago)
Love it, thank you. I'm actually not finding android as bad as I'd thought it would be. Yes, a lot of questions, but as its going in I'm finding it not too bad. The emulator SEEMS to be working fine too! Thanks again.
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
07/09/13 10:49 PM (12 years ago)
Final question for the day, I promise..! How do I open plugin's, i'm after the code in BT_viewUtilities ?! All the best.
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
07/09/13 10:50 PM (12 years ago)
Scrap that, got it :)
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.