Android的布局重力 [英] Android Layout Gravity

查看:132
本文介绍了Android的布局重力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个布局,其中以人像模式layout_gravity应center_vertical,当我在风景模式下,它应该是顶部。

当我有center_vertical在横向模式下的布局定位在中心,我可以向上滚动。

人像

景观

我怎样才能做到这一点在一个单一的布局文件,而不是有多重的。

布局code:

 < XML版本=1.0编码=UTF-8&GT?;
<滚动型的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@可绘制/ splash_background_gradient>

    <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =center_vertical
        机器人:paddingTop =20dip
        机器人:paddingBottom会=20dip
        机器人:方向=垂直>

        < ImageView的
            机器人:ID =@ + ID / SplashLogo
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_gravity =中心
            机器人:layout_marginBottom =40dip
            机器人:SRC =@可绘制/ splash_logo/>

        <按钮
            机器人:ID =@ + ID / FacebookLogin
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_gravity =中心
            机器人:layout_marginLeft =25dp
            机器人:layout_marginRight =25dp
            机器人:背景=@可绘制/ splash_facebook_button_selector
            机器人:重力=中心
            机器人:填充=0dip
            机器人:文本=@字符串/ splash_facebook
            机器人:文字颜色=#FFFFFF
            机器人:TEXTSIZE =8PT
            机器人:TEXTSTYLE =黑体/>

        <的TextView
            机器人:ID =@ + ID / SplashSignupLabel
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_marginBottom =5DP
            机器人:layout_marginLeft =28dp
            机器人:layout_marginRight =28dp
            机器人:layout_marginTop =20dip
            机器人:文本=@字符串/ splash_signup_label
            机器人:文字颜色=#e9e9e9
            机器人:TEXTSIZE =6PT
            机器人:TEXTSTYLE =黑体/>

        <按钮
            机器人:ID =@ + ID / SplashSignupButton
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_gravity =中心
            机器人:layout_marginLeft =25dp
            机器人:layout_marginRight =25dp
            机器人:背景=@可绘制/ login_button_selector
            机器人:文本=@字符串/ splash_signup
            机器人:TEXTSTYLE =黑体/>

        <的TextView
            机器人:ID =@ + ID / SplashLoginLabel
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_marginBottom =5DP
            机器人:layout_marginLeft =28dp
            机器人:layout_marginRight =28dp
            机器人:layout_marginTop =20dip
            机器人:文本=@字符串/ splash_login_label
            机器人:文字颜色=#e9e9e9
            机器人:TEXTSIZE =6PT
            机器人:TEXTSTYLE =黑体/>

        <按钮
            机器人:ID =@ + ID / SplashLoginButton
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_gravity =中心
            机器人:layout_marginLeft =25dp
            机器人:layout_marginRight =25dp
            机器人:背景=@可绘制/ login_button_selector
            机器人:文本=@字符串/登录
            机器人:TEXTSTYLE =黑体/>
    < / LinearLayout中>

< /滚动型>
 

解决方案

从布局的资源文件夹复制你的布局,并将其粘贴在布局 - 土地的文件夹,并改变那些需要在第二个设置。

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

Landscape

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>

解决方案

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.

这篇关于Android的布局重力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆