Android: pixel-perfect layouts for each resolution - android

I want to create an app with pixel-perfect graphics for each resolution (I'm going to support only 3 or 4 of them). In my main activity I created new layout and selected 800x600 from available qualifiers. I edited it and then I created folder "layout-1280x720" for another resolution. I copied activity_main.xml from "layout-800x600" to "layout-1280x720" and edited new copy. But now when I run it in android emulator at 1280x720 I see layout from 800x600.
How can I create different layouts for each exact resolution?

Please visit this URI
http://android4beginners.com/2013/07/appendix-c-everything-about-sizes-and-dimensions-in-android/
You can see there a proper approach for your issue.

It's actually close to impossible to do that, because android doesn't have percent dimensions, of course you can use weight coefficients, but it won't be the solution. I will recommend you to use this app, which overlays your template over everything. It makes layout creating much easier and faster.

Related

Support different screen sizes in Android

I am getting very confused on how to support all different Android screen sizes. I have already checked this answer, this site, the official documentations and many other answers but still I am confused so please don't mark this as Duplicate.
I already created layout-sw120dp, layout-sw160dp, layout-sw240dp, layout-sw320dp, layout-sw480dp (I only need to support up to 6 inches so I don't create layout-sw600dp).
What do I have to do is just have one layout and just copy it in each different folder so Android will do the selection on its own or I also need to change values in each layout?
What do I have to do is just have one layout and just copy it in each different folder or I also need to change values in each layout?
You start by deleting the layout-sw120dp, layout-sw160dp, layout-sw240dp, layout-sw320dp, and layout-sw480dp directories that you created. Or, at least, ignore them for now.
You then start implementing your UI, putting layout resources in res/layout/.
Then, for those layouts that need to be different in certain scenarios, you then create a directory representing the size when you want a different layout. Copy the layout from res/layout/ into the new directory, and then modify that copy to reflect whatever changes you want.
In other words, one copy of every layout is in res/layout/, and you override where needed with additional, modified copies in specific directories where you need the UI to change.
If you want to use the same layout for each and every screen density, you don't need to create different folders. Use just one simply called "layout" and the system will interpret it for every density. However, this could lead to strange layouts on certain physical devices depending on their screen size and density...
Another point you have to be aware of, if your application supports orientation changes, is that you have to design layouts for portrait and lanscape orientations. This is done by duplicating a folder used for a density and add "-port" or "-land" to inform the systen which one must be used according to the actual orientation of the device your app is currently running on.
If you want to precisely define your app look and feel, you have to customize your layout for each density. And if you use bitmaps, you will have to customize them either (for example, your app icon should be defined with different sizes to keep a good looking for each screen density). Just as for the layout, you have to create "drawable-..." folders to contain the corresponding versions of your bitmaps.
This is an answer that's been an issue from old ages and for which you'll see lot many answers but which is not a one fit all type still. What I did come up with though when faced with the same issue was to use PercentRelativeLayout. This is a relatively new feature that was started from Android support version 23.0 (android sdk manager), and one of the big game changers according to me, since it allowed
developers to specify their blocks relative to the layout size Percentage-wise. And since it is in terms of percent, this fits all screen sizes with varying dimensions, but while maintaining the ratio.
Ofcourse this method involves some trial and error and a lot of experimenting, but I found this method to be the easiest to implement and which took out the headache of maintaining the dimensions for various screen sizes.
Few tutorials to get you started :
https://www.tutorialspoint.com/android/android_relative_layout.htm
https://guides.codepath.com/android/Constructing-View-Layouts

supporting multiple screen sizes and orientation

Please help me... I create my first project in android and no any experience in android UI. ![enter image description here][1]
res/layout/main.xml.
res/layout-land/main.xml
res/layout-large/main.xml
res/layout-large-land/main.xml
res/layout-xlarge/main.xml
res/layout-xlarge-land/main.xml
res/layout-sw600dp/main.xml
res/layout-sw600dp-land/main.xml
res/layout-sw720dp/main.xml
res/layout-sw720dp-land/main.xml
this folder's layout structure is correct for handling every screen
size?
and android version <3.2 and >3.2 supports for this?
If this is your first project in android, focus on building your initial UI without worrying about alternate adaptations for other devices. Many times 1-2 layouts is enough (portrait/landscape) - If you stick to DP/SP units.
Once your initial UI is in place, test different devices in the emulator to see if you need to create any adaptations.
Give a good idea about your question while asking .
As a beginner you can just use res/layout and if u want to use in landscape mode use res/landscape mode.
Try to Start with these two . You Will Need Other Options Later .
Also Use sp , dp for size like font size or height .

How do I organize my activity layouts with the smallest possible layout folders?

I have three layout files for an activity:
layout-small-ldpi
layout-normal-mdpi
layout (for the rest)
When visiting the activity with a normal-hdpi mobile, Android pulled the layout from normal-mdpi/. Then I put the generic layout into a new configuration: layout-normal-hdpi/ which seems to do the trick of pulling that layout for sizes>=normal && density>=hdpi. It also seems to pull the normal-hdpi layout with devices of large-mdpi configuration which is fine by me.
Will this solution cause me any troubles? Is there any better way for keeping the number of layout folders to a minimum of 3? I have read the docs but it's nice to have a second opinion.
If I understand you correctly, you want to support as many screen sizes as possible with as little layouts as possible. Here is a good link to a PDF that should help you out.
Scaling Android Apps with White Paper

Set multiple images on screen supporting multiple density

I am developing a simple game part of application where i need to create a game using lots of images of different different shapes, imagine ice breaker game where i need to break ice using hammer.
So when i think of setting layout with different types of ice images and that too which support all different densities,i get stuck and not able to understand how i set my layout, whether with Relative / Linear Layout so that it give me same result in all size of android devices except tablets.
I hope you understood the problem, support of all density, around 500-600 images with different shapes, which layout to use and one more thing .apk size is also big matter for me as there are other lots of images other than for this game.
Please read the Screen Supports for the better understanding.
Use configuration qualifiers as explain in that Document for the Different Layout. And Also put the XML file with in that layout drawable directory.
that help me. So it will be also helpful to you.
Be free to comment if you have any dought.
Edited
You can set the layout for the different screen support as like below:
See the Image Below:

Program that has proper layout on all device android

I am currently writing a remote control program to control a robot on all android devices.
I am trying to display the layout to fill the screen fully on different sizes. My first try was on a samsung 10.1' tablet and it was working well but when I port it to smaller devices like 4.3' the layout goes wrong. I am thinking of creating several layouts to match with different screen sizes but how do I check which layout to set according to screen sizes?
I have tried getwidth and getheight but it only works after you have set the layout.
Please give me a short sample code if possible as I am very new to this.
If there are any other better ways please advice me on it.
Please note that I am using API level 8, android 2.2.
Go through this and this. Basically, you create layout for various screen, each with same name. They are put in different folders (each named according to factors like- landscape, portrait, screen density and screen size). OS will decide on it's own about which layout to use.
This is great article about that. But in overall, never expect the screen to be any static size. But if you're deciding to create layout for each size, you don't have to worry about choosing the best layout, android will do it for you if you provide multiple versions of same layout.
You do not have to check the screen dimensions. Just create your layouts, and Android will automatically pick the correct one for your screen size, orientation, API level, etc. See here for more details: http://developer.android.com/guide/practices/screens_support.html

Categories

Resources