0

Android でマルチ dpi をテストしていますが、レイアウト xml ファイルは次のようになります。

<?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>

480x800 mdpi(160) シミュレーター (7 インチにスケーリング) で実行すると正常に動作しますが、480x800 hdpi シミュレーターでは、EditText を画面の下部近く (ほぼ 600px) までパディングします。 240 / 160 ? また、4インチに拡大しても画面サイズと変わらないようです。異なる画面密度でパディングを機能させる方法は? どうもありがとう!

4

1 に答える 1

1
How to let padding work under different screen density? 

次のように、さまざまなフォルダーにさまざまなパディングを使用して、さまざまなレイアウト xml を作成できます。

res/layout-mdpi 
res/layout-hdpi

次に、Android は適切なレイアウト xml を選択します
。dp(Dip) について dp
は、現在のデバイス画面でビューに適切なサイズが与えられることを保証します。たとえば、 が表示されたビューは、ディスプレイ上とディスプレイ上で広くlayout_width="100dp"測定されますが、ビューはほぼ同じ物理スペースを占有します。100 pixelsHVGA@160 density150 pixelsWVGA@240 density

詳細については、この複数画面のサポートを参照してください。

于 2011-03-30T02:44:34.667 に答える