How to create layouts properly (Android) - android

i´m pretty new to android development and creating different layouts for each resolution wasn´t really that easy for me.
So, I was able to optimize my app for most devices (in eclipse), but i´m still having some problems here and there:
do I really have to copy the same images with different resolutions for each device-resolution into the respective folder? I´m currently using the hdpi, large-hdpi, mdpi and xdpi folders...
isnt it possible to use one drawable-folder and just scale the images down?
is there an extra drawable-folder for those 5.1in (WVGA)/5.4in (FWVGA) devices? In eclipse they´re labeled with mdpi, but these devices are using the large-hdpi folder and those images are too big, but perfect for i.e. nexus 7.
i´m also using 4 different layout-folders (layout-sw360dp, sw480dp, sw600dp & sw720dp). Is that a proper way to create a layout for each device-group?
Hopefully someone is able to help me with this.
Thanks in advance!

1) Yes you have to copy the images with different resolutions for each device resolution into respective folder. Because if you don't do that you will have unexpected results on different screen sized i.e. misplaced controls and layout will not be proper.
2) If you scale the images then they will get stretched or squeezed and you will not get proper result on the screen.
3) Folders sometimes behave differently on different devices. Sometimes they don't use the folders they are intended to use.
4) Yeah! as recommended in the documentation it is a good practice to use different folder as you can't be sure of the screen sizes in android.

Related

Trouble with implementing app for different screens on Android

I am about to publish my first app and I am extremely confused about making it look nice on different screens.
At first I thought mdpi/hdpi/etc. values (dimensions) folders would suffice when I saw that the screen was showing the exact same things on S4 Mini & S6 Edge, hdpi & xxxdpi respectively.
Well, how is this even possible when I haven't specified other than the main dimensions.xml file?
From what I understand from playing with the layout editor on different devices is that screen size matters more (?).
So far I have created a mdpi/hdpi/xhdpi/xxhdpi folder but it seems that that's far from enough.
What other folders should I make? Do I need many layout folders too?
I would use this scalable size unit library. It's really easy to use and it will automatically scale your widgets for various screen sizes.
Here's the link if you are interested: https://github.com/intuit/sdp

How to create separate layouts for Nexus 5X and Nexus 6P?

Since the launch of Nexus 5X and Nexus 6P, I have noticed my layout designed previously looks relatively small on these new two devices. I tried creating multiple Layout resource folders but nothing seems to be working efficiently. After going through multiple tutorials and blogs, I am still struggling with this issue. Any kind of help or tutorial would be really appreciated.
Using multiple layouts is the correct way to solve Layout problem only. Besides, you also need adding suitable drawable resolutions and dimensions.
See more:
Make sure to use dp and sp as your scale.
Make sure if the correct layout folder is being picked by the mobile phone (see note below)
Resolution of image assets must be proportional to the dpi - check the Android icon resolution requirements and scale your image assets accordingly.
*To determine if the app does pick the layout folder you intend the app to pick - you could change the background for different layout folders and determine which one it picks *

Supporting different devices with different layout

I have doubt in making the layout for other deices I mean to support different devices of different resolutions. I have made an application and it is working well on hdpi devices and I tested on Samsung Galaxy grand which has 320dp-460dp and 480px-800px.
May application is looking awesome on this device. but when I run on other devices its gone bad. SO I am suggested to make the folder like layout-large, layout-xlarge and layout-xxlarge but there is a lot of difference in this link and this link
So this makes me confuse , with which name I have to make the layout folders to support all devices ?? please tell me
and also tell me I have some hard coded values in my layout such as left margin 13 dp to make my design look perfect on hdpi device should I make it more in other xhdpi devices ???
and also which devices comes in layout-large folder and so on please answer my both confusion , thanks in advance
I use Google's code as an example of how to do stuff. The docs on "Supporting multiple screen" is a bit old and outdated. The best way to keep up with the current conventions is to follow other's codes.
Here is the source code for the Calendar app. Yes, there a lot of different folders for layouts/drawable/values but you have to consider the fact that there are a lot of devices with varying sizes and pixel densities.
Also, why do you want to make many folders for layout? You make a few layouts and let the values and drawables do the rest of the work. Hope it's helpful.
IF you are interested in knowing which device falls under which folder, then check this figure from the Official Android Guide:
Of course you need to know the actual size or density of the physical device

Android drawable folder image size

I am pretty new to Android and I am doing a pet project in order for me to learn Android. Basically I want to display six images on the screen. I have noticed the drawable folders and I have 256x256px inages in the drawable-xhdpi folder. In the Nexus 5 preview in android studio it looks great but in Nexus 7 (2012 version) the images are very small and both Nexus 5 and Nexus 7 are using the drawables-xhdpi folder.
This is my code:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageMars"
android:id="#+id/imageJupiter"
android:src="#drawable/jupiter"
android:contentDescription="#string/content_desc_jupiter"
android:layout_toRightOf="#+id/imageVenus"
android:adjustViewBounds="true"/>
How can I make the images look bigger on the Nexus 7, but without being to big for the nexus 5?
And I want the application to look good on other devices too, so I don't think that setting a fixed size for the image(70dp x 70dp for example) would work
Thank you
Best practice in Android is to provide the correct size images in each of those folders and let the system choose the best one based on the device. Supporting Multiple Screens is a must read.
Basically what happens is the system will navigate to the folder that would best satisfy its screen, if the image it needs is there, great; if not it will navigate to the next best folder and so on. If it cannot use the best for the device it will use the best you gave and try its best to make it look as good as possible. Sometimes this isn't so great. It can stretch or shrink images into an ugly state.
So again, the best thing to do is provide multiple sizes of the same image in each of the folders to get the desired results.
Edit (response to commentary):
Guess not. In Eclipse/ADT I've got
Nexus 4 # 768x1280 - Normal xhdpi
Nexus 7 (2012) # 800x1280 - Large tvdpi
So regardless of "larger" the fact remains that they're pulling resources from different drawable folders. The tvdpi is said to be not needed in most apps because it's somewhere between mdpi and hdpi and those folders are usually sufficient. Maybe add the tvdpi and see if it varies at all and make sure you've correctly scaled your images based on the folder.
Edit:
Alright, the behavior you're experiencing is normal - unfortunately I suppose - but I found a solution. I've personally never faced this because I learned it's better to utilize the extra area on larger screens to put more content on there.
Anyway, as if you didn't have enough drawable folders, you need another drawable folder, or three, along with more images - yeah!
In my previous edit I mentioned the "Normal" and "Large" modifiers of the drawable folders as they appear in Eclipse ADT. Well, it turns out that those are valid folders as well and certain devices with small, large, or xlarge screens will use them.
I was able to get larger images by adding another res directory titled drawable-xlarge-xhdpi; this is for the Nexus 10. I enlarged your jupiter file to 512x512 and...
Note: I read that this isn't a recommended solution but could not see anywhere in the Android docs that warned against it. Research may be necessary!
You should provide different image sizes for different display sizes/resolutions. That what the drawable-100w, etc folders are.
If you don't want to do that but you still want the images resized to use all the available space, you will have to do resize the ImageView elements programmatically.

Android muliple screen support?

I have to design an application which to support under three resolution. for that i use the code in manifest
and also create three folder layout , layout-large, layout-small for supporting three resolution, correspondingly i put the different resolution of image in drawable-hdpi ,drawable-ldpi ,drawable-mdpi , but whenever i run the app in different resolution it going to take low resolution image instead of different resolution i use.
I don`t know where i made the mistake, whether i have to add some code in layout xml or not. I also search the android developer forum and i do the application design as they insist.
Any one suggest some idea to achieve this.Thanks
There are two things you could check: have you set the minimum SDK version of your app to use version 4 (Android 1.6) support for this started?
Secondly, the layout-large and layout-small folders are designed for different sized screens (think tablet vs phone), and not resolution. If you're changing the resolution (DPI) of the device, you'll need to use layout-hdpi, layout-ldpi etc.
Further, if it's only the images you're changing, you should be placing the different images in drawable-hdpi, drawable-ldpi etc, and not layout-xxxx. If on a supported device, Android will pick the image from the correct folder, so you'll only have one layout folder (or 2 if you use layout-land)
Some (or all :S) of these points are covered in this link, to another question on StackOverflow. Try to use the search function before asking a question. Also, you'll find people are more receptive to providing answers to users with higher accept percentages.
Android - layout-large folder is been ignored
Edit: for multiple screen support, also look at Fragments to better organise and fit your content for both large and small screen devices (dev.Android, worked example)

Categories

Resources