布局调整查询{中心水平+垂直居中} [英] Layout alignment Query {Center Horizontal + Center Vertical}

查看:119
本文介绍了布局调整查询{中心水平+垂直居中}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

必须是很简单的解决,但我不能够解决这个问题。

我要对齐的顶形象和log_in_box,让整个事情出现在屏幕的正中心(水平+垂直居中)。

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android机器人:layout_width =match_parent
    机器人:layout_height =match_parent机器人:方向=垂直>

    < LinearLayout中的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:方向=垂直
        机器人:layout_gravity =center_vertical | center_horizo​​ntal>

        < ImageView的机器人:layout_width =match_parent机器人:layout_height =WRAP_CONTENT机器人:SRC =@可绘制/ ic_launcher
            机器人:contentDescription =/>

        <的LinearLayout机器人:ID =@ + ID / log_in_box机器人:layout_width =match_parent机器人:layout_height =WRAP_CONTENT
            机器人:方向=垂直>
            < EditText上的android:layout_width =match_parent机器人:layout_height =WRAP_CONTENT机器人:提示=用户ID
                机器人:inputType =文本/>

            < EditText上的android:layout_width =match_parent机器人:layout_height =WRAP_CONTENT机器人:layout_marginTop =10dp
                机器人:提示=密码的Andr​​oid版本:inputType =textPassword/>

            <复选框机器人:layout_width =match_parent机器人:layout_height =WRAP_CONTENT机器人:检查=真
                机器人:文本=记住我的Andr​​oid版本:layout_marginTop =10dp/>

            <按钮机器人:ID =@ + ID / log_in机器人:layout_width =match_parent机器人:layout_height =WRAP_CONTENT
                机器人:layout_marginTop =10dp机器人:文本=登录/>
        < / LinearLayout中>

    < / LinearLayout中>

< / LinearLayout中>
 

目前看

解决方案

 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>

    <的LinearLayout
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=垂直
        机器人:layout_centerInParent =真正的>

        < ImageView的机器人:layout_width =match_parent机器人:layout_height =WRAP_CONTENT机器人:SRC =@可绘制/ ic_launcher
            机器人:contentDescription =/>

        <的LinearLayout机器人:ID =@ + ID / log_in_box机器人:layout_width =match_parent机器人:layout_height =WRAP_CONTENT
            机器人:方向=垂直>
            < EditText上的android:layout_width =match_parent机器人:layout_height =WRAP_CONTENT机器人:提示=用户ID
                机器人:inputType =文本/>

            < EditText上的android:layout_width =match_parent机器人:layout_height =WRAP_CONTENT机器人:layout_marginTop =10dp
                机器人:提示=密码的Andr​​oid版本:inputType =textPassword/>

            <复选框机器人:layout_width =match_parent机器人:layout_height =WRAP_CONTENT机器人:检查=真
                机器人:文本=记住我的Andr​​oid版本:layout_marginTop =10dp/>

            <按钮机器人:ID =@ + ID / log_in机器人:layout_width =match_parent机器人:layout_height =WRAP_CONTENT
                机器人:layout_marginTop =10dp机器人:文本=登录/>
        < / LinearLayout中>

    < / LinearLayout中>

< / RelativeLayout的>
 

Must be very simple to solve but I'm not able to solve this.

I want to align the "top image and log_in_box", so the whole thing appear in exact center (Horizontal+Vertical center) of the screen.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent" android:orientation="vertical">

    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"
        android:layout_gravity="center_vertical|center_horizontal">

        <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/ic_launcher"
            android:contentDescription="" />

        <LinearLayout android:id="@+id/log_in_box" android:layout_width="match_parent" android:layout_height="wrap_content"
            android:orientation="vertical">
            <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="User ID"
                android:inputType="text" />

            <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp"
                android:hint="Password" android:inputType="textPassword" />

            <CheckBox android:layout_width="match_parent" android:layout_height="wrap_content" android:checked="true"
                android:text="Remember Me" android:layout_marginTop="10dp" />

            <Button android:id="@+id/log_in" android:layout_width="match_parent" android:layout_height="wrap_content"
                android:layout_marginTop="10dp" android:text="Log In" />
        </LinearLayout>

    </LinearLayout>

</LinearLayout>

Current Look

解决方案

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:layout_centerInParent="true" >

        <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/ic_launcher"
            android:contentDescription="" />

        <LinearLayout android:id="@+id/log_in_box" android:layout_width="match_parent" android:layout_height="wrap_content"
            android:orientation="vertical">
            <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="User ID"
                android:inputType="text" />

            <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp"
                android:hint="Password" android:inputType="textPassword" />

            <CheckBox android:layout_width="match_parent" android:layout_height="wrap_content" android:checked="true"
                android:text="Remember Me" android:layout_marginTop="10dp" />

            <Button android:id="@+id/log_in" android:layout_width="match_parent" android:layout_height="wrap_content"
                android:layout_marginTop="10dp" android:text="Log In" />
        </LinearLayout>

    </LinearLayout>

</RelativeLayout>

这篇关于布局调整查询{中心水平+垂直居中}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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