0

画像にこのコードを使用しています:

<ImageView android:src="@drawable/logo"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_marginLeft="50dip"/>

ロゴを中央に配置したいのですが、レイアウトマージンの左の値を変更して確認して配置することで実行できますが、中央に配置するコマンドはありますか?

4

4 に答える 4

1

使用してみてください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ます。

于 2012-05-30T15:11:02.270 に答える
0

レイアウトの他の部分によっては、その親の重力を center_vertical|center_horizo​​ntal に設定して使用できます。

于 2012-05-30T15:16:51.907 に答える
0

要素android:layout_centerInParentを使用して、画像を親 (コンテナー) の中央に配置することもできます。

于 2012-05-30T15:18:12.213 に答える
0

さらに良いこと:画面のサイズの画像ファイルを使用します(周囲に空きスペースがある場合でも)

于 2012-05-30T15:46:06.450 に答える