How to support different screen size in android
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/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
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" />
And also check out my SO answer.
Supporting multiple screen size - Android
I just did something very similar. To stretch the app without creating new layouts I used dimensions set in XML
res/values/dimensions.xml
res/values-sw600dp/dimensions.xml -> 7+ inches
res/values-sw720dp/dimensions.xml -> 10+ inches
Dimensions are resources files:
<dimen name="default_padding">11dp</dimen>
You can increase the dimensions by about 30% in the 600 and 720 file.
Then simply used @dimen/default_padding
in your layout and it will be scaled
Regarding images, either you make sure you have all your assets in all densities, or you set fixed size to you ImageView
's and appropriate scaleType
Creating Same UI Supporting Different Screen Sizes?
Use SDP - a scalable size unit library for supporting different screens.
An android SDK that provides a new size unit - sdp (scalable dp). This size unit scales with the screen size. It can help Android developers with supporting multiple screens.
Here is the LINK
multiple screen support in android
http://developer.android.com/guide/practices/screens_support.html
You have to add different folder for different layout in res folder --> hdpi,mdpi,ldpi and for large screens you xhdpi(for Tablet) and large-hdpi or xlarge (for NXzoom). Also set Images and text size different in different layout as per screensize...
Supporting multiple screen sizes in Android by using multiple layouts
Android provides a very good way to support multiple screen sizes. It's called weights. You should use LinearLayout
weights and check out your Graphical View to figure out how you want to resize.
Completely avoid:
- Calculating your resolutions and screen sizes. You will end up in a mess.
- Multiple layouts across dpi's.
Trust me, all the apps I have developed until now (12) have been done using weights with 1 layout file across all platforms. It works, and works like wonder.
Edit:
I also never use more than 5dp for padding and 10dp for margins. This way I keep the code clean and Android weights take care of my free space.
For more about weights, check out this question. It is really well explained to start with.
Edit Again:
Think about it. You are assuming dp to be the "same" in terms of physical mm (millimeters) for all phones. But it is not. In fact X and Y 1 dp may mean something different in "mm". dp is "not" consistent. Be careful when using code like 100dp and setting hardcoded widths and heights. And even worse, multiple layout files. You will get into a lot of code maintenance nightmares with those.
Related Topics
Make an Android Button Change Background on Click Through Xml
Adb Server Version (36) Doesn't Match This Client (39); Killing
How to Change the Size of a Switch Widget
Starting the Android Emulator in Sdk Tools, Revision 12
How to Get the Android Path String to a File on Assets Folder
Why Do I Get Com.Google.Android.Gms.Common.Api.Apiexception: 10:
Android - R Cannot Be Resolved to a Variable
Is There a Simple Example of the Popupwindow Class Using Android V2.0
"Canvas: Trying to Draw Too Large Bitmap" When Android N Display Size Set Larger Than Small
Android Intent for Playing Video
How to Use Radiogroup in Listview Custom Adapter
How to Get Android Device Screen Size
How to Change Focus Color of Edittext in Android
Android Broadcastreceiver, Auto Run Service After Reboot of Device
How to Provide Animation When Calling Another Activity in Android