6

画面の中央に配置したい画像があります。私の期待にもかかわらず、それは水平方向に中央揃えされていますが、垂直方向には中央揃えではありません。つまり、画像が画面上部に接触します。

同じレイアウトはサンドボックス プロジェクトでは問題なく表示されますが、残念ながら実際のプロジェクトではそうではありません。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    <!-- ... -->
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >
            <ImageView
                android:id="@+id/progress2"
                android:src="@drawable/wait2"
                android:layout_centerInParent="true"
               android:layout_centerHorizontal="true"
               android:layout_centerVertical="true"
                android:visibility="visible"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />
        </RelativeLayout>

台詞

               android:layout_centerHorizontal="true"
               android:layout_centerVertical="true"

もちろん不要ですが、どちらの場合も物事は機能しません。

どんな提案でも大歓迎です。

編集: ビューがから表示されることが関連しているようInputMethodServiceです。

4

2 に答える 2

6

私はちょうど同じ問題を抱えていました。使った

android:layout_centerInParent

AndroidStudioプレビューと4.3デバイスのNexus 4で動作しました。しかし、2.3 の Galaxy S1 では機能しませんでした。

RelativeLayout で中央に配置したいレイアウトをラップし、重力属性で中央に配置することで修正しました。

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

<RelativeLayout
    ...

それは両方のデバイスで機能しました。

于 2013-09-17T11:20:12.113 に答える