I'm developing an app in android and I have to support all different screen sizes and density. So i've created different folder for layout : layout-small layout-large
and layout
.
Then I've created different folder for image: ldpi, mdpi
and hdpi
. In all drawable folder the image must be with different size true? I ask this cause of I have a phone with screen size large and density medium, the image shown will be smaller and they will not take the right size?
Android adjust by it self you can put separate image for different folder if you want to use different images for high resolution devices and other device. Otherwise just put in one drawable,layout folder only for some images you can make 9-patch also.
you need permission in manifest for multiple screen support link
<supports-screens android:resizeable=["true"| "false"]
android:smallScreens=["true" | "false"]
android:normalScreens=["true" | "false"]
android:largeScreens=["true" | "false"]
android:xlargeScreens=["true" | "false"]
android:anyDensity=["true" | "false"]
android:requiresSmallestWidthDp="integer"
android:compatibleWidthLimitDp="integer"
android:largestWidthLimitDp="integer"/>
Use sdp library which is provided in Github
Adding to @ud_an
It is not a good practice to create different folders for layouts. Create your layout such that it works fine with all the screen sizes. To achieve this, play with the layout attributes. You only need to have different images for hdpi, mdpi and ldpi types. The rest will be managed by android OS.
you can create bitmaps for the highes resolution / size your application will run and resize them in the code (at run time)
check this article http://nuvornapps-en.blogspot.com.es/
Beginning with Android 3.2 (API level 13), size groups (folders small, normal, large, xlarge) are deprecated in favor of a new technique for managing screen sizes based on the available screen width.
You can figure out the dimensions of the screen dynamically
Display mDisplay= activity.getWindowManager().getDefaultDisplay();
int width= mDisplay.getWidth();
int Height= mDisplay.getHeight();
The layout can be set using the width and the height obtained using this method.
It sounds lofty,when it comes to supporting multiple screen Sizes.The following gves better results .
res/layout/layout-w120dp
res/layout/layout-w160dp
res/layout/layout-w240dp
res/layout/layout-w160dp
res/layout/layout-w320dp
res/layout/layout-w480dp
res/layout/layout-w600dp
res/layout/layout-w720dp
Chek the Device Width and Height using Display Metrics
Place/figure out which layout suits for the resulted width of the Device .
let smallestScreenWidthDp="assume some value(Which will be derived from Display metrics)"
All should be checked before setContentView().Otherwise you put yourself in trouble
Configuration config = getResources().getConfiguration();
if (config.smallestScreenWidthDp >= 600) {
setContentView(R.layout.layout-w600dp);
} else {
setContentView(R.layout.main_activity);
}
In the top,i have created so many layouts to fit multiple screens,it is all depends on you ,you may or not.You can see the play store reviews from Which API ,The Downloads are High..form that you have to proceed.
I hope it helps you lot.Few were using some third party libraries,It may be reduce your work ,but that is not best practice. Get Used to Android Best Practices.
Source: Stackoverflow.com