How to make my android game fit to all screen resolution? - android

I wanted to create a small game on android and then I realize that there is a problem with a screen resolution. I don't know how to make my game's control (Buttons, Textview, etc) will look good to all the screen resolution like (tablet and normal android device) that have different pixel. Like if I design layout for android phone and then if I run it on tablet then buttons, or any controls will look small. So the question is that how to make it (all controls) look more fit and good for any different pixel or resolution device?

You have to create seperate layouts for phablets tablets etc. create 5 folders under res directory.
layout-ldpi
layout-hdpi
layout-mdpi
layout-xdpi
layout-xxdpi
Then copy your file which by default in your layout folder and paste it in a all above folders. Then you have toh manually set the contents for different views . It is a very very boring tedious task

Related

How to make layout compatible with different android devices in android studio?

I am designing an app with a .jpeg background and with text views on particular places on the screen. I designed this for my nexus 6 and used dp for the widths and heights of text views and margin-left and margin-top. What my understanding of dp is that it changes with every device according to screen size and density. So it should work on different phones according to the value of dp for them.
But this is not the case. When I run that app on a different phone (nexus 5) the layout is all messed up. I tried using the different resources and qualifiers for different screens (large, small, normal). But the problem still prevails. The app considers both nexus 6 and nexus 5 as large screens. How do i fix this?
this is not the best solution i guess.
i guess your layout is just on the layout folder. i don't know if the first device you tested the layout is large or small but what you should do is create another folder named layout-sw600dp. this folder is used by tablets. the folder layout is used my phones and smaller devices. you could also create the layout-land and layout-sw600dp-land folders for the landscape orientation.
dp do change depending on the device but if your layout gets messed up then i guess the layout called by that device doesn't fit its resolution. i guess dp becomes smaller if the device is bigger and vice versa.

wxga android layout >600dp

I have an andoid layout which I want to display on tablets and phones.
I've created folders and layouts for
layout
layout-land,
layout-sw600dp,
layout-sw600dp-land,
layout-sw720dp,
layout-sw720dp-land,...
For most screens this works ok until I load a 4.7 wxga screen
I understand the relationship between density and size but what am I supposed to do to build a consistent layout when a wxga screen wants to run use the sw720dp layouts ?
If I specify text size based on a dp specific folders xml layout I simply can not get what I want. Am I missing something fundamentally simple . How can I make this layout work on a small screen with high pixel density and a large screen with the same number of pixels?
Here's what it looks like
edit : not enough reputation points to post images ;( post almost pointless now
It would be good to know what device is it. Especially its dp resolution. If you know it then you can create a layout-swXXXdp folder for it. If you don't know then I propose to put something in the layout files and check which is loaded on that device. E.g. in layout folder put a TextView with text "layout normal", in layout-sw600dp put a TextView with text "layout sw600dp" and so on. Please note that you can use other numbers as well for the layout folder name like layout-sw456dp.
I think in this way you can find the proper layout folder for that device.

Is it necessary to create "small, normal, large and xlarge android xml layouts" folders if i want my application to run of all Android devices

I am developing an Android Application that supports all kind of Android devices like mobiles and tablets. But it's time consuming to create multiple folders (small, normal, large and xlarge android xml layouts) to support all the Android devices. Is there any way to build an android app that runs on all android devices without creating these folders:small, normal, large, xlarge etc?
You only need to create unique layouts (ie. *layout_mdpi* ) if you want something unique for that particular screen size.
If you want to use the same layout on all different screen sizes, you will only need to create a single layout (in the layout folder).
Only if you want to customize a particular layout would you need a new FOLDER in layouts (named: layout_mdpi) in that folder you would have multiple copies of customized layout with same name (ex. my_layout.xml)
To clearly answer your question - you will only need the layout folder and no other ones in your casel
Ex.
res\layout\my_layout.xml // this folder is all you need if this layout will work on all screen sizes
res\layout_mdpi\my_layout.xml // you ONLY need this if you are presenting something unique on this screen size.
In Android we need to maintain different folders for the layouts with different resolution reason behind it is the use or the resolution of the Android Device on which the application gonna execute.
small Resources for small size screens.
normal Resources for normal size screens. (This is the baseline size.)
large Resources for large size screens.
xlarge Resources for extra large size screens.
Android OS select the specific layout it self by checking the compatible device and its resolution.
So, better to create folders to support in multiple screens
For More Info refer this
Is there any way to build an android app that runs on all android devices without creating these folders:small, normal, large, xlarge etc
Consider this, you have a button (with match_parent) that stretches full width of a screen in portrait mode of a 4 inch phone, that's fine it looks alright, but then that same layout on a 10 inch tablet in portrait is now 3-4inch wide, that's not great looking.
"So what" you say, make it wrap content, okay then so the button now only fills up part of the width on phone, still looks okay but then on a tablet you have huge amount of space now either side of the button, maybe that's looks okay, maybe not.
Maybe same button on a smaller screen takes up too much space?
Now apply the above to every single layout element in your app.
Do you think it'll look good, using the same layout, do you think your users will be okay with an app that was so little care to its UI and UX?
SO, in conclusion, yeah it's possible to only use one eg normal, for all devices but it'll probably look terrible on most of them.

How can I fix android tablet's width and height

I am making android application in tablet using fragments so that I arranged 8 buttons vertically in 10.1 tablet it is showing fine but in 7.1 tablet only 5 icons it is showing.
So How can I manage height and width properly in all tablets ... please help
Remember to write different xml layouts (with same name) and place to different folders: layout-large, layout-normal, layout-small and layout-xlarge. Same is with drawables (different size images) and values (different type padding and other values). These folders are for different phone/tablet types with various resolution and screen size. If you do it, then you can easily manage layout for small device and not touch big screen devices. Device is picking xml file automatically so it's good practice to place xml files in different folders for various phones.
More information you can find in http://developer.android.com/guide/practices/screens_support.html
You can use different layout for different screen sizes. You can also add different buttons and other drawable also. Please see the link
Supporting Multiple Screens
You can write different xml layouts using different folders:
For example:
res/layout
res/layout-sw600dp //used by 7''
res/layout-sw720dp //used by 10''
Also you can use the same layout with the same component but with different dimensions.
You can use #dimen/my_dimen notation, and then put your my_dimen in different folders like:
res/values/dimens.xml
res/values-sw600dp/dimens.xml
and so on..
Official doc: http://developer.android.com/guide/practices/screens_support.html

In Android, image sizing while supporting multiple screen sizes

In my android app, I want to support multiple screen sizes. I realize that for Android "large" means a lot of the current phone screens at 480 x 800 pixels as well as a 7" tablet like the Nexus 7 which has 800 x 1280 pixels. But I'd like to create 2 separate layouts for those two display sizes. I've found that rather than using res/layout-large, using res/layout-h800dp gives me greater control of which size screen uses what layout. (I'm using a portrait orientation, hence h800dp) The problem I'm having is this: sometimes the h800dp layout uses the images in the drawable-mdpi folder, and sometimes it uses the images in the drawable-hdpi folder. I'm using the same syntax in the xml to call the images: `android:src="#drawable/image", but in one activity it looks in the mdpi drawable folder, and in the next activity, it looks in the ldpi drawable folder. Is there any way to get the h800dp layouts to always look in the ldpi folder?
This link explains nearly everything regarding screen properties (DPI, physical size, resolution, etc.)
What you may be able to do is specify folders like layout-large-hdpi, layout-large-mdpi, and layout-large-ldpi.
Experiment with blending these types together in folder names.

Categories

Resources