how to handle xml UI for diffrent-2 screen resolution android
hi i have made UI in xml for displaying in view it is looking good in 480*800 resolution size screen but for small size 320*480 or medium screen the UI looking distorted means Buttons are not in its real position.i save all the images in ldpi,hdpi and mdpi folder and also give permission for screen support
below is my xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mainmenuimage"
>
<Button android:layout_marginTop="230dip"
android:text="currentloc"
android:focusable="true"
android:background="@drawable/mainmenubtn"
android:id="@+id/btn" android:layout_height="50dip"
android:layout_width="110dip"
android:layout_marginLeft="100dip"/>
<Button
android:text="Filter"
android:id="@+id/filter"
android:layout_height="50dip"
android:layout_width="110dip"
android:layout_marginLeft="100dip"
android:layout_marginTop="6dip"
android:background="@drawable/mainmenubtn"/>
<Button开发者_StackOverflow
android:text="keyword search"
android:id="@+id/keysearch"
android:layout_height="50dip"
android:layout_width="110dip"
android:layout_marginLeft="100dip"
android:layout_marginTop="6dip"
android:background="@drawable/mainmenubtn"/>
</LinearLayout>
and manifest is:
<supports-screens
android:anyDensity = "false"
android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
/>
so how to handle layout for diffrent screen ,i have read alreday all tuts in android developer side....but not got any...pls help thanks
This article descripes what to do: http://developer.android.com/guide/practices/screens_support.html
For example, 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 medium, high, and extra high density screens.
res/layout/my_layout.xml // layout for normal screen size
res/layout-small/my_layout.xml // layout for small
res/layout-large/my_layout.xml // layout for large
res/layout-xlarge/my_layout.xml // layout for extra
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
Ideally, the hdpi version of your button should be 1.5 times bigger than the mdpi (baseline) version.
In other words, if the height of your background mainmenubtn image is 50 px in mdpi, the hdpi version needs to be 75 px.
res/drawable-mdpi/mainmenubtn.png
res/drawable-hdpi/mainmenubtn.png
If you're on Windows, just right-click on each of those two image files in Explorer and select properties to take a look at their dimensions.
Also, 50 pixels is a bad choice for a height in Android. Stick to the standard heights as much as you can. There are good reasons those dimensions were chosen in the first place. Take a look at the following dimensions for standard icons (I know your buttons are not square, they're rectangle, but bear with me for a moment).
You don't have to turn your button into a square, definitely not, but if you're trying to use a size like 50 px and 75 px for a particular height, you might as well use 48 px and 72 px instead (for both the mdpi and hdpi versions respectively).
And if you're trying to use 110 px and 165 pixels for width (again, for mdpi and hdpi respectively), you should pick instead 104 px and 158 px (or something like that). In other words, you should try to maintain the original aspect ratio of the rectangle you had in mind, but also ensure that the resulting dimensions are divisible by 4.
Notice that all the screen sizes of any phone and almost all the standard icon dimensions are divisible by 4 as well (except for some the smallest icons where pixels are at a premium). That's not a coincidence. This is because dimensions are generally easier to scale and operate on when they're divisible by 4. Also note that the ldpi version is 3/4 the size of the baseline mdpi version, so that's one more reason for you to make sure that the baseline mdpi dimensions are at least divisible by 4 (even if you chose not to make the ldpi version itself divisible by 4).
And by the way, do not mess with making different layout files until you've gotten this density problem taken care of. If you're lucky, your problem may just be different densities and your application make look fine with just one normal layout file for all the different screen sizes.
And also on a different note, know that small screen sizes are only 3.4% of the Android handset Market as of September 2, 2011, and that proportion is likely to decrease over time, so keep that in mind in case you're trying to spend too much time making the layout look just right on a small-sized emulated screen.
精彩评论