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

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

    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>

    效果图:

  • 相关阅读:
    spingboot项目在windows环境中运行时接收参数及日志中文乱码
    应用node-webkit(NWJS)把BS架构的网址封装成桌面应用
    AndroidStudio离线打包MUI集成JPush极光推送并在java后端管理推送
    AndroidStudio离线打包MUI
    Centos7环境下搭建Nginx+Lua+Redis进行数据存取
    Nginx各项配置的含义
    MyBatis动态批量插入、更新Mysql数据库的通用实现方案
    spring+springMVC+Mybatis架构下采用AbstractRoutingDataSource、atomikos、JTA实现多数据源灵活切换以及分布式事务管理
    《spring boot》8.2章学习时无法正常启动,报“ORA-00942: 表或视图不存在 ”
    Win10系统使用Docker安装oracle并通过Navicat for oracle进行登录
  • 原文地址:https://www.cnblogs.com/0927wyj/p/5321087.html
Copyright © 2011-2022 走看看