Android学习之布局管理器嵌套

线性布局管理器 (LinearLayout)里嵌套相对布局管理器(RelativeLayout)
线性布局管理器分为水平布局和垂直布局
水平布局(horizontal):组件从左往右进行排列,所有组件占一行,每一个组件占一列
垂直布局(vertical):组件从上到下进行排列,左右组件占一列,每一个组件占一行
相对布局管理器是按照组件的相对位置进行摆放的,我们可以指定一个组价相对于另一个组件的位置

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.mypc.android.MainActivity"
    android:paddingBottom="16dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp"
    android:orientation="vertical">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:textColor="#FF0077FF"
        android:textSize="20sp"/>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="账号/手机号/邮箱/QQ号"
        android:paddingTop="20dp"/>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="密码"
        android:inputType="number"
        android:paddingTop="10dp"/>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/button1"
        android:layout_marginTop="30dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="注册"
        android:layout_marginLeft="70dp"
        android:textSize="20sp"
        android:textColor="#FF0077FF"
        android:backgroundTint="#FF8247"/>
    <Button
        android:layout_toRightOf="@id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登录"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="50dp"
        android:textSize="20sp"
        android:textColor="#FF0077FF"
        android:backgroundTint="#FF8247"/>
    </RelativeLayout>>


</LinearLayout>

效果图:

我们需要注意的就是怎么通过布局管理器的特点以及嵌套来控制各组件的位置以及布局管理器嵌套的代码格式
控制注册按钮与上面编辑框的距离代码android:layout_marginTop="30dp"
控制注册按钮与容器左边的距离代码android:layout_marginLeft="70dp"
控制登录按钮相对于注册按钮的距离代码android:layout_marginLeft="50dp"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值