开发者

Dip in xml does not work for different screen density in android simulator

I'm testing multi dpi in android, and the layout xml file seems like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/new_album_bg">
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="@string/hello" />
    <RelativeLayout android:gravity="center"
        android:paddingTop="400dip" android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <EditText android:background="@drawable/name_text_bg"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:gravity="center" />
    </RelativeLayout>
</RelativeLayout>

When I run it on a 480x800 mdpi(160) simulator (scale to 7 inches), it works fine, but on a 480x800 hdpi simulator, it PADDING the EditText down to the near bottom of the screen, nearly 600px, is that 400dip x 240 / 160 ? And It seems has no difference with screen size even I scaled it to 4 开发者_StackOverflowinches. How to let padding work under different screen density? Thanks a lot!


How to let padding work under different screen density? 

you can create different layout xml with different padding in different folders like

res/layout-mdpi 
res/layout-hdpi

Then the android will select the appropriate layout xml
About dp(Dip)
dp will guarantee that the view is given an appropriate size on the current device screen. For instance, a view with a layout_width="100dp" will measure 100 pixels wide on an HVGA@160 density display and 150 pixels on a WVGA@240 density display, but the view will occupy approximately the same physical space.

For more details refer this Supporting Multiple Screens

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜