How to support multiple screen sizes in android - android

I am having a problem displaying my layout in 5" or smaller screens .The smaller height of phone spills bottom views out display . I tried creating layouts using sw320dp and different dimens folder but app seems to take that smallest layout only for all type of sizes. I am unable to map the layouts properly . All I need is to make the size of views smaller in small screens.

-You should use ConstraintLayout for Create a flexible layout
-You should use Different dpi icon for different phones like mdpi,hdpi,xhdpi,xxhdpi,xxxhdpi
-you can also take reference from Google's Documentation
https://developer.android.com/training/multiscreen/screensizes

Add this code in your Android Manifest xml
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />

Try this library it will be helpful
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.intuit.ssp:ssp-android:1.0.6'
This library will help to create flexible view items as per device screen sizes.

You can use constraint layout, it will effectively adjust most of your views. Along with that, as a precaution, add scrollview in layouts where you think you have too many views just so they don't go out of screen bounds on smaller screen sizes.
Constraint layout doc: https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintLayout

Related

Android Development related to Xml layouts

I have made a layout for an app,it runs fine on my phone but when I use a smaller size phone to run it the user interface changes and is not in accordance.For example the buttons go out of screen or their order of placement changes.What should I do?
you have to develop different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens.
For layouts
res/layout/mainactivity.xml // layout for normal screen size ("default")
res/layout-small/mainactivity.xml // layout for small screen size
res/layout-large/mainactivity.xml // layout for large screen size
res/layout-xlarge/mainactivity.xml // layout for extra large screen size
res/layout-xlarge-land/mainactivity.xml // layout for extra large in landscape orientation
For drawables
res/drawable-mdpi/ic_icon.png // bitmap for medium density
res/drawable-hdpi/ic_icon.png // bitmap for high density
res/drawable-xhdpi/ic_icon.png
put following code in the Manifest
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
Kindly look at the following links for more reference
https://developer.android.com/training/multiscreen/screensizes.html -> Diff Screen Size
https://developer.android.com/guide/practices/screens_support.html -> Diff Screen Supports
Few tips for single layout:
Design your views relatively(Check Relative-Layout and Frame-Layout) .
Take the advantage of weight(Check Linear Layout).
Use scroll view if your layout height is big.
For Ex: If you want to put some buttons(for say 2) on the bottom of the screen just use RelativeLayout as parent and inside that LinearLayout with alignparentbotton=true after that you can define buttons, you also can use weight on buttons to equally align horizontally.
This is one of the way to support different screen sizes. You need to create layout folders depending on screen sizes. (like layout-normal, layout-large, etc). Place your xml layout files in each folders. Don't use hard dp/sp values.
Go through
Supporting Multiple Screens for more understanding.
Use weights inside Layouts to adjust the views properly.
It is the most reliable way to do it.

setting correct size for android screen

Pleas can some one help me understand what values I should use to fit most android screen sizes.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.airrocketapps.macuser.airrocketapps">
<supports-screens
android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"
android:requiresSmallestWidthDp="320dp"
android:compatibleWidthLimitDp="320dp"
android:largestWidthLimitDp="320dp"/>
<application
Please have look at this article Android Layouts for different Screens
you have to made layout for every screen sizes if you want to handle all types of screen i,e landscape,potrait etc. You must use wrap_content or match_parent for views to fit into present screen or activity.
If you don't specify it will "support", as in launch on, any device with which the rest of the config is compatible. You can remove the support-screens tag completely. But there's a big difference between your layouts _fitting) on screen and them being appropriately designed for those screens.
Checkout Supporting Multiple Screens, Supporting Different Screen Sizes, and Designing for Multiple Screens in the Android docs.

Guidelines to support multiscreen android layout

I am currently working on an Android app. I am not an UI guy, and just trying out which number fits the best when I make the layout xmls like below:
<ImageView
android:id="#+id/my_icon"
android:layout_height = "30dp"
android:layout_width = "wrap_content"
android:layout_gravity = "center_vertical"
android:scaleType="centerCrop"
/>
I know that 30dp will work ok on xxhdpi devices because that is what I am using and testing, but I think this will cause trouble when the screen resolution is lower (say, a mhdpi device).
I am wondering if there is any guideline on how to make a layout support different res?
You can find giudelines in following links
How to support different screen size in android
http://developer.android.com/training/multiscreen/screensizes.html
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/training/basics/supporting-devices/screens.html
Here you can find some guidelines:
http://developer.android.com/design/style/devices-displays.html
For Different screen size, The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens.
res/layout/layout.xml
res/layout-small/layout.xml
res/layout-large/layout.xml
res/layout-xlarge/layout.xml
res/layout-xlarge-land/layout.xml
res/drawable-mdpi/icon.png
res/drawable-hdpi/icon.png
res/drawable-xhdpi/icon.png
The following code in the Manifest supports all dpis.
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />

Android application for Tablet

I have developed an application that is to be run on android Tablet as well. It is working on android phones perfectly. When I ran it on Tablet, it did not expand on whole screen. It just covered a area equal to a mobile device. I want that it also runs on Tablet and cover the whole screen as running on mobile device. Do I have to create two different designs for each type and at run time before using design, I would have to check it whether it is android phone or table?
Add below code in android manifest
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
Add the following block of code in your manifest file after the <uses-sdk>tag:
<supports-screens
android:xlargeScreens="true"
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
Note: Add the android:xlargeScreens="true" attribute if and only if your minSdkVersion is equal to or more than 9.
In addition to adding this block of code, follow this link. Also suggest you to go through the following links:
Supporting Multiple Screens
Supporting Different Screen Sizes
Supporting Different Densities
Hope this helps.
please try
<uses-sdk android:minSdkVersion="8" android:maxSdkVersion="11"/>
<supports-screens android:anyDensity="true" />
in Manifest.xml before tag.
I hope it may be help you.
Yes, ideally you'll design layouts targeted to tablets. You don't have to, but you can. See here for details. Your app is running in "screen compatibility mode". See here for info about that.
I think you used fixed width and height for any view or layout in your app, to support a fixed resolution of your mobile device.
If you use fill_parent, wrap_content and weight property, such things in your app, the app will fill entire screen of any android device. Once review your code.
Small example
Assume device has no rotation. Your device has resolution 320 X 240. you have to fill 3 buttons horizontally, you can put each button width=100 and remaining as margin/padding of layout. If you run same app on device with resolution 640 X 480, some space will come after 3 buttons. If you use width=fill_parent and layout_weight=1 for these 3 buttons and parent's layout_width=fill_parent, on any resolution these 3 buttons will fill the entire width of screen.
I hope it may help you.

Scaling on android devices beyond 480x800

I have a small Android app which works fine on resolutions up to WVGA (480x800), however beyond this the layouts don't scale (for instance for the Galaxy TAB 1024x600) but appear in the top in the middle (with black borders down sides and at bottom). The layouts look fine in Eclipse at these resolutions.
What Am I doing wrong?
Am I missing something in the manifest? Do I need to supply high resolution resources?
Try putting this in your manifest.
<supports-screens android:xlargeScreens="true" />
http://developer.android.com/guide/topics/manifest/supports-screens-element.html#xlarge
putting
<uses-sdk android:minSdkVersion="4" />
In the correct place in my manifest solved the issue. For some reason I had placed it under <application>.
I've created a tool that allows you to scale/adjust your layouts for tablets and small screen devices and made a blog post about it here: http://onemanmobile.blogspot.com/2012/04/how-to-scale-your-android-layouts-to.html
Basically, defining your layouts in dp units is not enough if you want your app to fit on all devices and tablets, since there's 4 different "density-buckets". The tool will allow your layouts to be converted into fitting these density buckets.
It will also explain in further detail how to make flexible view components.

Categories

Resources