Reputation: 12009
I know this questions has been asked quite a few times. But I couldn't find the bebest possible solution to my query.
I have followed every step given in the developer support of android.
Support Multiple Screen
Putting images in different folders for different sizes. Making different layout folders for device screens. But the problem persist in the devices ranging from 4.7 inches to 5.0 inches. The layout gets quite disturbed on these devices.
What is the best and possible way to overcome that.
Upvotes: 1
Views: 4257
Reputation: 1
If you need an absolute measure of your the screen's density you can use the following code:
Got this from somewhere sometime ago, but still relevant. Enjoy it !
DisplayMetrics metrics = new DisplayMetrics();
try {
WindowManager winMgr = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE)
;
winMgr.getDefaultDisplay().getMetrics(metrics);
}
catch (Exception e) {
metrics.density = 1;
}
The value metrics.density now contains a measure of the screen's density with 160dpi density as a the 'baseline'. More info can be found here:
http://developer.android.com/reference/android/util/DisplayMetrics.html#density
Upvotes: 0
Reputation: 4387
Basically some devices belongs to large or normal group but they have so much difference in height and width for example- Nexus-4 4.7"
having dimensions 768x1280
and one other device 5.1"
having dimensions 480x800
. So you can create layouts folders depending upon height and width. For example- layout-w480dp, layout-w720dp or layout-h800dp or layout-h1280dp
. Then set views in those layouts according to your requirement.
Upvotes: 3
Reputation: 428
Please refer below link:
http://developer.android.com/guide/practices/screens_support.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. you could use different size of the layout files in res folder and also vary for drawable images based on the density..
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
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="false"
android:xlargeScreens="true"
/>
<compatible-screens>
<screen
android:screenDensity="ldpi"
android:screenSize="small" />
<screen
android:screenDensity="mdpi"
android:screenSize="normal" />
<screen
android:screenDensity="xhdpi"
android:screenSize="large" />
<screen
android:screenDensity="xhdpi"
android:screenSize="xlarge" />
</compatible-screens>
And followed by any activity use this lines..
android:configChanges="orientation|screenSize|keyboardHidden"
Upvotes: 0
Reputation: 6166
Please refer these link:
Multipal screen size handling!
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" />
Upvotes: 0
Reputation: 346
If you are designing any forms go for Match Parent, dont go for hardcore pixel positions. Use Relative layout.
P.S Please tell more about your compatibility issues?
Upvotes: 0