3

我正在尝试创建一个布局,其中在纵向模式下 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>
4

2 回答 2

2

从资源的“layout”文件夹中复制您的布局并将其粘贴到“layout-land”文件夹中,然后在第二个文件夹中更改您需要的那些设置。

于 2011-10-29T08:10:10.363 回答
0

您在横向模式下正确查看,您必须创建一个名为 layout-land 的新布局文件夹,并根据适合您的应用的元素应用新的定位。

于 2011-12-14T06:47:41.497 回答