How can I fix android tablet's width and height - android

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

Related

Different layout for 5 and 4 inch Android devices

I have an Android application with one layout file. I have different layout files for different densities, i.e., layout-hdpi, layout-mdpi, etc. I also have different dimens files in corresponding value directories (values-mdpi, values-hdpi, etc).
My problem is that I would like to use different layouts for 4 and 5 inch screen devices. I am testing on two physical a 4 inch and a 5 inch and both devices use the layout from the /res/layout folder and the dimens file from the /res/values-hdpi/ folder (in other words, they use the same resources).
Is there a way to make the 4 inch device use a different dimens.xml file - if not automatically, can this be done programmatically?
You can use something like layout-sw320dp or similar. This will differentiate layouts based on minimum display width.
Here is much more about it:
https://developer.android.com/guide/practices/screens_support.html#NewQualifiers
Density is not related to size, they tell you how many pixels there are in on square inch of screen, not how may inches of space there are in the screen. you should use size related resources. for example layout-w500dp folder would be used for screens that have at least 500dp of width.this should help

Android - standard layout folder, which screen size?

I'm implementing an application and I want to support all screen sizes. I have 4 layout folders: layout, layout-small, layout-large and layout-xlarge.
Which screen size supports the standard layout folder? Is it even necessary?
Which screen size supports the standard layout folder?
In your case, it will depend on what files are in what directories.
Let's say that you have main.xml in layout/, and not in any of the other three candidates. Then, setContentView(R.layout.main) will use the copy in layout/.
Now, let's say that you add a revised version of main.xml in layout-xlarge/. On an -xlarge device, Android will use the layout-xlarge/ version of main.xml, and on other screen sizes, Android will use the layout/ version of main.xml.
Now, let's say that you add a third main.xml version, this time in layout-small/. Android will still use the layout-xlarge/ copy of main.xml for -xlarge devices. However, all other devices will use layout-small/, and the layout/ copy of main.xml will be ignored. Android will not try to shrink a layout from a larger size (e.g., -xlarge layout on a -normal device), but it will try to expand a layout from a smaller size (e.g., a -small layout on a -normal device).
What I tend to do is use layout/ for:
Layouts that do not need different versions for different sizes
Layouts to be used on -normal devices (as I rarely support -small)
I then use layout-large/, layout-xlarge/, or their Android 3.1+ replacements (e.g., layout-w720dp/) for layouts to be used on larger screen sizes.
However, that is just my particular style, and you are welcome to do what you want, within the usage rules described above.
using modern notation is a better solution:
/layout // for phones
/layout-sw600dp // for 7 inch tablets
/layout-sw720dp // for 10 inch tablets
In popular:
Mdpi screen smartphone is cheap
Hdpi screen smartphone is expensive.
If you use layouts only mdpi folder, this layout will be used for all screens
Legend:
layout-small = ldpi
layout = mdpi
layout-large = hdpi
layout-xlarge = xhdpi

Android background based on screen size

I'm creating an Android application, and want different background images for phone sized screens and tablet sized ones. I already have different resolution images for different resolutions (mdpi, hdpi etc.). The challenge is that most tablets use mdpi, but some phones might use it too.
I've tried to do some research, but only it seems to be possible to define screen sizes in the layouts, e.g. res/layout/layout-large. Does that mean I have to create a separate xml for tablets, linking to a #drawable/tablet-background? Or is there any other solutions, either xml or programmatic?
mdpi, hpdi etc. refers to screen density and that's independent from the device being a tablet or a phone. If I understood correctly, what you're trying to do is to use different background images for tablet and for phones.
There are three ways:
Create an xml layout for tablet and an xml layout for phone using layout-large, layout-xlarge folders
Using the same xml layout (except for an element id) in layout and in layout-large folders and change the background programmatically using something like this:
public boolean isTablet(){
return (findViewById(R.id.tablet_view) != null);
}
where tablet_view is an element id present only in the layout-large xml layout.
Another trick: Determine if the device is a smartphone or tablet?
and want different background images for phone sized screens and
tablet sized ones
Try the qualify the drawable folder with the desired screen size and also the density value for the target device, for example drawable-large-mdpi. The screen size must come first based on the configuration qualifiers table.

Best way to define Android layout files for multiple devices?

What is the standard/best way to define sizing for elements in Android layout files to account for Android devices with all types of screens?
For example: I've been using a LinearLayout to arrange multiple child elements (TextViews, Buttons) one after the other horizontally or vertically for a ListView. However, on a smaller device, I may want to scale the elements down or shrink some elements but keep the others fixed.
I'd appreciate input. Thanks
There's an entry in the android dev guide for that: http://developer.android.com/guide/practices/screens_support.html
You can use drawables in drawable-hdpi, drawable-mdpi and drawable-ldpi. Test those in different screens in the emulator and tweak the sizes appropriately
Please read supporting multiple screens.
In a nutshell: It's very easy. You can create subfolders of each folder in the resources (like layout-small, layout-large, layout-hdpi), and add different versions of your layout. The system will always fall back to the layout folder if none of your specializations (hdpi, large, etc) match.

Supporting multiple screens across different dpi and screen sizes

I have a two circles in a background image and I want to put two buttons in them. I am using relative layout. I have created several layout folders and images using guideline (layout, layout-large etc). But still the buttons are somewhat up or down in different actual devices. I am assuming this is because of Android default screen density bucket. Because if I provide only one layout for 320 to 479 dpi screen, It is possible that there could be a lot of devices in between. And my only layout for this range is surely going to be distorted? How do you design for supporting multiple devices? Thanks for you help in advance!
Add all the listed dimens.xml in vlaues folder for your project and manage them accordingly
values-sw320dp
values-sw360dp
values-sw480dp
values-sw600dp
values-sw720dp
This will definitely solve your problem of
supporting multiple devices.

Categories

Resources