Гравитация макета Android

Я пытаюсь создать макет, в котором в портретном режиме layout_gravity должен быть center_vertical, а когда я в ландшафтном режиме, он должен быть сверху.

Когда у меня есть center_vertical в ландшафтном режиме, макет располагается в центре, и я могу прокручивать вверх.

Портрет

введите здесь описание изображения

Пейзаж введите здесь описание изображения

Как я могу сделать это в одном файле макета и не иметь нескольких.

Код макета:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/splash_background_gradient" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:paddingTop="20dip"
        android:paddingBottom="20dip"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/SplashLogo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="40dip"
            android:src="@drawable/splash_logo" />

        <Button
            android:id="@+id/FacebookLogin"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:background="@drawable/splash_facebook_button_selector"
            android:gravity="center"
            android:padding="0dip"
            android:text="@string/splash_facebook"
            android:textColor="#FFFFFF"
            android:textSize="8pt"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/SplashSignupLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="28dp"
            android:layout_marginRight="28dp"
            android:layout_marginTop="20dip"
            android:text="@string/splash_signup_label"
            android:textColor="#e9e9e9"
            android:textSize="6pt"
            android:textStyle="bold" />

        <Button
            android:id="@+id/SplashSignupButton"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:background="@drawable/login_button_selector"
            android:text="@string/splash_signup"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/SplashLoginLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="28dp"
            android:layout_marginRight="28dp"
            android:layout_marginTop="20dip"
            android:text="@string/splash_login_label"
            android:textColor="#e9e9e9"
            android:textSize="6pt"
            android:textStyle="bold" />

        <Button
            android:id="@+id/SplashLoginButton"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:background="@drawable/login_button_selector"
            android:text="@string/login"
            android:textStyle="bold" />
    </LinearLayout>

</ScrollView>

person Harsha M V    schedule 29.10.2011    source источник
comment
Рассмотрите возможность использования включения. Имхо было бы намного проще.   -  person user999717    schedule 29.10.2011
comment
Как насчет поставить ScrollView?   -  person Adil Soomro    schedule 29.10.2011
comment
@Адиль у меня уже есть   -  person Harsha M V    schedule 29.10.2011
comment
@HarshaMV: тогда вам придется сделать макет земли.   -  person Adil Soomro    schedule 29.10.2011


Ответы (2)


Скопируйте свой макет из папки ресурсов «layout» и вставьте его в папку «layout-land» и измените те настройки, которые вам нужны, во втором.

person Bobs    schedule 29.10.2011

если вы правильно смотрите в ландшафтном режиме, вам нужно создать новую папку макета с именем layout-land и применить новое позиционирование элемента в соответствии с тем, что хорошо выглядит для вашего приложения.

person Gaurav Agrawal    schedule 14.12.2011