4
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView              
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/wallpaper" />
</RelativeLayout>

のサイズ@drawable/peetscoffee_wallpaperは 640x480 ですが、水平方向に中央揃えされていません。どうすればこれを修正できますか?

4

1 に答える 1

11

の代わりにandroid:gravity="center"、またはを試してください。android:layout_gravity="center"centerHorizontal="true"

ただし、サイズが に設定された画像でこれが適切に動作するかどうかは疑問です。 (たとえば)wrap_contentを使用して画像のスケーリング方法を定義し、ではなくに設定することをお勧めします。現在の実際の Android デバイスのサポートよりも大きいです。または、使用しているイメージを縮小して、デバイスが作業を行う必要がないようにします。android:scaleTypefitCenterfill_parentwrap_content640x480320x480

于 2009-04-29T19:45:22.527 に答える