2011-10-29 127 views
3

我想創建一個佈局,其中在肖像模式下layout_gravity應該是center_vertical,當我在景觀模式下它應該是頂部。Android佈局重力

當我在橫向模式下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> 
+0

考慮使用include。這將是一件容易的事。 – user999717

+0

如何放置一個'ScrollView'? –

+0

@Adil我已經有一個 –

回答

2

從資源的「佈局」文件夾複製您的佈局,並將其粘貼在「佈局 - 土地」的文件夾,並改變自己的第二個需要設置。

+0

thnaks :)想知道是否有工作 –

0

您在橫向模式下正確看待,您必須創建一個名爲layout-land的新佈局文件夾,並根據您的應用看起來很好的方式應用元素的新位置。