Android Layout Gravity

2019-02-24 12:35发布

I am trying to create a layout where when in Portrait mode the layout_gravity should be center_vertical and when i am in Landscape mode it should be top.

When i have center_vertical in landscape mode the layout is positioned to the center and i can scroll up..

Portrait

enter image description here

Landscape enter image description here

How can i do this in a single layout file and not having multiple ones.

Layout code:

<?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楼-- · 2019-02-24 12:58

Copy your layout from "layout" folder of resources and paste it in the "layout-land" folder and change those settings you need in second one.

查看更多
Rolldiameter
3楼-- · 2019-02-24 13:20

you proper look in landscape mode ,you have to create a new layout folder named layout-land and apply new positioning of element according to that which looks good for your app.

查看更多
登录 后发表回答