zoukankan      html  css  js  c++  java
  • 布局管理器之相对布局(二)

    这次示例代码是相对布局中兄弟组件之间,设置按钮的位置,难度:*****,一定要注意有同方向和反方向之分:

    1.同方向

    1)layout_alignLeft 同方向左对齐

    2)layout_alignRight 同方向右对齐

    3)layout_alignTop 同方向顶部对齐

    4)layout_alignBottom 同方向底部对齐

    2.反方向

    1)layout_above 在相对组件的上边
    2)layout_below 在相对组件的下边
    3)layout_toRightOf 在相对组件的右边
    4) layout_toLeftOf 在相对组件的左边

    注意:可以用相对的组件的id来设置

    代码示例:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮"
            android:layout_centerInParent="true"
            android:id="@+id/bt"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮"
            android:layout_alignTop="@id/bt"
            android:layout_toLeftOf="@+id/bt"
            /><!--相对于第一个按钮即兄弟而言直接用"@id/bt"-->
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮"
            android:layout_alignLeft="@id/bt"
            android:layout_above="@+id/bt"/>
            <!--above在..之上,上面的顶边与下面的底边对齐反方向-->
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮"
            android:layout_alignLeft="@id/bt"
            android:layout_below="@+id/bt"/>
        <!--below 在..之下-->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮"
            android:layout_toRightOf="@id/bt"
            android:layout_alignBottom="@+id/bt"/>
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮"
            android:layout_toRightOf="@id/bt"
            android:layout_below="@+id/bt"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮"
            android:layout_toRightOf="@id/bt"
            android:layout_above="@+id/bt"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮"
            android:layout_toLeftOf="@id/bt"
            android:layout_below="@+id/bt"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮"
            android:layout_toLeftOf="@id/bt"
            android:layout_above="@+id/bt"/>
    
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="输入框"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="10dp"
            android:paddingLeft="10dp"
            android:id="@+id/et"/><!--padding内边距-->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="OK"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/et"
            android:id="@+id/ok"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cencel"
            android:layout_below="@+id/et"
            android:layout_toLeftOf="@+id/ok"
            android:layout_marginRight="20dp"
            /><!--margin外边距-->
    
    </RelativeLayout>

    效果图:

  • 相关阅读:
    c语言面试基础题
    fwrite(&stud[i],sizeof(struct student_type),1,fp)的基本含义
    对于文件操作函数的记录
    将字符串s1复制到字符串s2。
    将键盘输入的几个数据存储到文件里的程序
    利用指针对二维数组进行遍历查找程序
    常见的C语言错误及程序的调试
    文件的基本操作函数及说明
    一个磁盘信息向另一个磁盘信息的复制
    常用流程图符号和基本流程图
  • 原文地址:https://www.cnblogs.com/fangchongyan/p/5356870.html
Copyright © 2011-2022 走看看