I'm trying to create an app where the header fits the entire width of the screen. I've got a Samsung Galaxy S8 Plus with a density of XXXHDPI according to Google's Device Metrics yet when I create an assets folder inside the 'res' folder named 'drawable-xxxhdpi' it doesn't load accordingly and fit the screen. Why is this? I've also tried putting it in the XHDPI and XXHDPI incase it scaled up but no. There's always a white space where the image is not scaling up.
The drawables folder has been created correctly and the XXHDPI works fine for XXHDPI devices but doesn't for bigger screens.
The white space on the right when testing on a bigger device
drawable and assets are independent directories . To load Drawable from asets you need to use Drawable.createFromStream().
Drawable d = Drawable.createFromStream(getAssets().open("images/sky.png"), null);
Other than that just make the hierarchy right and use it in conventional way. asset should be parallel to res not inside res.
Asset should be used to additional pre-bundled files not for images. because if you do this you can not provide multiple screen support.
So create Assets inside app/src/main/assets/.
And drawable inside res.
You might wanna check out these links Where should put Assets and Where should put Drawables.
Related
I have an android application, In which home page comprises of 8 ImageViews, they act as menu options for users, So where should I put the multi-density images for these ImageViews in custom drawable folders(ldpi,mdpi,hdpi,xhdpi,xxhdpi,xxxhpi) or drawableV21 or drawableV24 ?
It changes due to your need. For images, you can design them for the highest resolution and put them in xxxhdpi folder. Android will automatically downscale resolution for other devices. Also, you can put different drawables for different resolutions. But they should have the same name.
For drawableV21, drawable24 depends on the version you want to run your app. if you put a drawable v24 and not put anything with the same name in the drawableV21 folder. Your app will crash below Android API24.
So you should use this folder to show different drawable or other assets for different API Versions and resolutions.
I’m new to Android programming and I’m stuck with a very specific problem. I want my application to run on multiple screen sizes and densities.
I have several real devices with different screen resolutions (Samsung Galaxy S7 Edge [xxxhdpi], Samsung Galaxy A5(6) [xxhdpi], Samsung Galaxy Note 10.1 tablet [xhdpi].
I made one background and scaled it down for every generalized density. I saved the files as “background.png” in separate folders like suggested in Supporting Multiple Screens.
After testing the APK on the devices, everything worked fine except the background on the S7. It will always load the next lower resolution bitmap (xxhdpi instead of xxxhdpi). I looked countless threads how to fix this problem but nothing worked so far.
The resolutions of my bitmaps are:
drawable-mdpi //320x480
drawable-hdpi //480x800
drawable-xhdpi //720x1280
drawable-xxhdpi //1080X1920
drawable-xxxhdpi //1440X2560
I hope that someone can help me on this one. I’m really losing my mind.
This is a little complex but I'll try to keep it simple. The android system chooses the right resources based on a lot of factors (which you can see when you create a new resource file under the "Available qualifiers" list) which you can group to create a resource shared by different configurations or use only one of them to specify one particular configuration. But you cannot control witch resource the device will use for the most part (there are some you can specify yourself ex: night mode). Your S7 probably uses the wrong resource because probably one of the settings for the display resolution is set at a lower setting (ex: battery saving modes lower resolution, gaming mode.. etc, accessibility settings). And if you want a tablet to use a different drawable then a phone then you should use the "smallest screen width" qualifier since you can specify different screen sizes in Dip(ex: sw320dp is a normal phone, sw440dp is a big pixel phone, sw720dp is a medium tablet and sw1048dp is a bigger tablet). Read more here
I'm also facing like this. My app only works on high resolution mobile only. Then I found that error. I placed my drawable on drawable-hdpi only . For every assets we have to place default drawable in drawable folder
put default drawable in that folder.
drawable
For handling images on the s7 device we can give height and width to the image view. Set the values for height and width from the dimens file. For handling s7 UI need to add the dimens-sw411 file and specify the height and width in that.
I am absolutly new in Android development (I am developing my first app so be patient) and I have the following doubt.
I have to insert a picture as background of a view into my application and this image have to be correctly shown on all the different devices having different screen size.
So I found this article: http://www.survivingwithandroid.com/2012/07/how-to-support-multiple-screen-in.html
My doubt is: what exactly I have to do in my project?
I think that I have to do the following steps (but I am absolutly not sure of it so I am asking to you):
1) Into the res folder of my project I create the following subfolder: drawable-hdpi, drawable-ldpi, drawable-mdpi, drawable-xhdpi
2) Then I use Photoshop to change the density of my picture and so I put the 120dpi version of my picture into the drawable-ldpi folder, the 160dpi version of my picture into the drawable-mdpi and so on.
Is it my reasoning correct? It ensure that my picture it is displayed at the same size on different screens?
I want to show this image in an Android (Java) app, but the app displays it as. How do I display the first image in an app without getting this blurring effect?
EDIT::
And how can I change the size with no blurring effect?, the imagen will show pixelated. Like this http://i.gyazo.com/18b227adb4c442b09152ca6ebc04c54c.png
To show image with the original size use layout_width="wrap_content" and layout_height="wrap_content". This is considering that your image is smaller than the screen in which it is to be shown. Also if you only provide image in your drawable-hdpi folder then the images in mdpi screen with be scaled by a predefined scale factor(possibly 2). Same case applies for other screen density. To avoid this scaling you can put your images in drawable-nodpi folder.
Note: the images you posted are not properly made(highly pixilated). Try optimizing the resolution and provide multiple resources.
At the moment I have just targeted my UI graphics for the hdpi resolutions for android and this works flawlessly, the graphics are designed with 3 resolutions in mind with only the background image being altered really. Problem is the plan was to use the same images for hdpi (480x800 and 480x854) and as well as mdpi (320x480). But when I test it for mdpi with the images in both the -hdpi and copied into -mdpi it doesn't scale them down, do I have to resize all the images and have them duplicated for the mdpi screens?
Sorry if this is not very eloquent it is the first time I have done any UI design for android and still don't understand it properly.
Android should correctly use the right image when you use R.drawable and your images are in drawable-hdpi, drawable-mdpi etc. Since that is what I think you've described as what you've done, it hints that maybe you've hardcoded a size? Are you using ImageView and set a size for them? If so, did you do it in Java code or in XML? If in Java code the values would be in pixels, so 50px on mdpi screens will look larger than on hdpi screens. If you used XML did you again set a size with px? If so, you should use dp.