画像にこのコードを使用しています:
<ImageView android:src="@drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dip"/>
ロゴを中央に配置したいのですが、レイアウトマージンの左の値を変更して確認して配置することで実行できますが、中央に配置するコマンドはありますか?
使用してみてくださいRelativeLayout
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/app_logo"
android:contentDescription="application_logo"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
のみを使用する場合はhorizonal alignment
、 のみを削除android:layout_centerVertical="true"
しXML resource
ます。
レイアウトの他の部分によっては、その親の重力を center_vertical|center_horizontal に設定して使用できます。
要素android:layout_centerInParent
を使用して、画像を親 (コンテナー) の中央に配置することもできます。
さらに良いこと:画面のサイズの画像ファイルを使用します(周囲に空きスペースがある場合でも)