Android Layout Gravity - PullRequest
       28

Android Layout Gravity

3 голосов
/ 29 октября 2011

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

Портрет

enter image description here

Пейзаж enter image description here

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

Код макета:

<?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>

Ответы [ 2 ]

2 голосов
/ 29 октября 2011

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

0 голосов
/ 14 декабря 2011

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

...