Different Screen Size [duplicate] - java

This question already has answers here:
Is there a way to create xxhdpi, xhdpi, hdpi, mdpi and ldpi drawables from a large scale image?
(19 answers)
Closed 5 years ago.
Hey guys i just wanna ask When ever we display a background picture in our activity we placed the picture in the drawable folder with sub different folder like
drawable layout_hdpi or layout_mdpi or layout_ldpi or layout_xhdpi
and there is a specific density and dimension for each folder so that it can support multiple devices etc .
i want to ask that do i need to modify my picture for each folder like if my picture dimension is 3000*3000
first i have to modify it to 720*1280 for xhdpi and then put it in layout_xhdpi folder then i modify it for hdpi i.e 400*800 dimension and so on ..
It will take much time to do .Is There is any other easy method
Thanks in Advance !!

You don't need to modify the image for each size. Keeping it to a standard size(eg-1920*1080) would do the work for most of the phones. However for phablets or tablets, you would have to modify the image. Also reduce the images from 3000*3000 to a smaller size as this would increase the app size drastically, would be useless and might cause PNG crunching to fail.

Related

i need to know what different between screen size and screen density

in my android app i need to support multiple screens (all sizes and all screens )
so i have read about density and screen size but i don't know what i should to choose when i creat another xml file for every single activity .. a four xml files depend on screen size like this :
res/layout/your_layout.xml (layout for normal screen)
res/layout-small/your_layout.xml (layout for small screen)
res/layout-large/your_layout.xml (layout for large screen)
res/layout-xlarge/your_layout.xml (layout for extra large screen)
or five files to support all density like what i do with drawable png files
plz help me to find the answer i need to what better and what the deference between them .
This is so simple like if you are using hard values like setText="22sp.Now it might good your test mobile but good for every mobile screen so you have to create four folder
**hdpi,xhdpi,xxhdpi,xxxhdpi**
Copy the same file in these 4 folders and adjust it. when the app runs on any mobile Android framework automatically detects the screen and gets one of them.
Note: if you are using not hard values like matchparent etc then no need to create 4 duplicate files of that.

How to proper use DPI resolutions

I know I need to use different DPI for images and all graphics stuff, but I just don't understand if I have to create the different drawable folders by myself or if there's a proper way to do it, and plus, what to use them for.
For instance I need to add a wallpaper, where should I put it? And of what resolutions? What are the pixels needed for each?
Tried to read the Google page about this, but didn't get much, thank you!
I have to create the different drawable folders by myself or if
there's a proper way to do it?
Assuming you're using Android Studio:
what to use them for.
from http://developer.android.com/guide/practices/screens_support.html:
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
In that page you have documentation for screen sizes and densities.
Basically, when you put, let's say, an image in an activity, it will render according to the device's density corresponding folder.
a wallpaper, where should I put it?
The best is to have an image for each density, but if you don't have those provided, you can put it in the drawable folder, without any density qualifier, which means that your resource is the same for every screen density.
For a quick way of knowing your device screen stats, download ScreenInfo.
"...I just don't understand if I have to create the different drawable
folders by myself"
no, you don't have to, but you can.
"... if there's a proper way to do it"
If you right click on res then select new then select Image Asset, Android Studio has an Image Asset tool that guides you through the whole process. This is how you import various UI elements in their correct dpi and densities.
"... what to use them for"
This is upto you. But if you set an ImageButton to an drawable with various drawable resources for different screen dpi, the correct dpi drawable will be chosen according to the device's screen dpi when the app is running.
"wallpaper..?"
Put that in drawable-nodpi or just the regular drawable

Android Game using drawable folders how?

I'm new at Android Game Development I already read (Dummies Android Game..., Sams Teach..).
I want to draw now several images (tiles) to create my map, but I also want that they are automatically scaled to the device screen as good as possible. At the moment I just know how to use images from folder drawable but they are not scaled to the screen...
I already saw some examples where they use xml files to get to images over R.id.... but for this I must use the xml as layout in the code and can't use something like this or?
//create the view object
view = new SurfaceView(this);
setContentView(view);
view.setOnTouchListener(this);
I'm a little bit confused... :(
How do other Game Programmer scale their images to the different device screens?
I would be very thankful for some examples!!!
You could let android scale the images for you automatically, but of course, the quality might not turn out the way you want, but it is less work on your part. If you want more control over the scaling of your images, the only choice is to manually create them and put them in their respective folders including the default folder (drawable folder without subfix), drawble-mdpi is for medium Dot-Per-Inch devices, such devices as 320x480 screen.
drawable-hdpi is the drawable folder for devices with a high density screen size such as 480x800 or 480x854 depending on the screen sizes as well. I am going to give you the threshold by which you use to tell if it is mdpi or hdpi so on
1.mdpi: 160dpi (dpi = Dot Per Inch, it is different from dp or dip which stands for density-independent pixel)
hdpi: 240dpi
xhpdi: 320dpi = 2 times mdpi, this includes devices such as galaxy s4 with a screen resolution of 1080x1900 depending on the screen sizes as well, you kinda get the idea of how big xhdpi is.
xxhpdi: 480dpi, this one is newer but you can be guaranteed xhdpi images will scale up to fit xxhdpi very nicely, generally, you dont need to create graphics assets for xxhdpi, xhdpi is good enough.
One rule you should remember is that, you should create images for xhdpi devices and scale down accordingly, not the other way around.
As for R.id.., the part after the "R" is called the resource type you want to reference, if it an id you put R.id, drawable use R.drawable, as in the setContentView() method, you have R.layout because you are referencing a layout resource. I hope this helps you a little
When you use xml for drawables these are located to the drawable/ folder and not the layout/ folder.
In order to use them you call R.drawable.name_of_your_drawable not R.id.... nor R.layout.....
Another way to avoid blurring in larger screens is to provide different resources for different screen dpis for this option you have to place your drawables to
drawable-mdpi/
drawable-hdpi/
drawable-xhdpi/
etc
Note: that when you use multiple folders each drawable must have the exact name in all folders and the system decides which to pick.

create a scaled image [duplicate]

This question already has answers here:
How to scale an Image in ImageView to keep the aspect ratio
(26 answers)
Closed 9 years ago.
I can load Images from my assets folder just fine, but now I want to scale the Image (originally 400 x 240, want it to be 800 x 480).
I can't do this with Bitmaps because of 2 reasons: (1), can't seem to create Bitmap from a file without knowing the whole path from C:\ to Assets folder, which is dumb since the whole path is gonna change depending on where app is installed; and (2), can't find a way to convert an Image to a Bitmap. And yes, i've looked up on StackOverflow how to try those/similar things, been looking them up and trying again and again for 3 days all day, no luck.
So how to scale Images? I don't understand why it's so hard to manipulate these things, and what is the difference between Bitmap and Image anyway?
Yes, I'm new to Java/Android as of 3 days ago, but I've done a lotta work in C# and other langs. PS, I know how to create and use Canvas and Paint objects. Ideally, I just need a Image scr_scale_image(Image img, int ScaleX, int Scale y) method.
thanks for any help.
try imagemagick, which provides an api for java (JMagick) - http://www.imagemagick.org/script/index.php

Android Photoshop PNG Icons appear large and stretched

I am developing for the Android. When I create icons in Photoshop (and convert them to PNG), they appear larger and stretched within my Android application. The emulator that I am using is medium density. Does anyone have some tips for how I can create my icons in Photoshop so that they appear normally on the Android?
Thanks!
The dpi of the PNG isn't relevant in this instance, only the actual pixel size. How are you displaying the images? If you're using an ImageView, try setting android:scaleType="none". If you're setting its width and height with wrap_content it shouldn't matter, but it's worth a try.
Also, if you're accessing them from the drawables folder, try placing them under a new folder called drawable-mdpi. Android should detect that the emulator is set to medium density, and automatically use the resources from the mdpi folder if they exist.
PNGs can store pixel size information (dpi). That's probably why you see the image larger and streched.
Check Photoshop's image size options, if necessary fix the print sizes so aspect ratio is conserved.
I also have this problem. I don't know why. I am using Mac. The png file produces by it is extremely large. For example, the normal size should be 8kb, but it's size is 48kb. If a use other editor to edit & save them, the size return OK. Seems that ps is saving some extra info into the png file.

Categories