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>

    效果图:

  • 相关阅读:
    windows安装kafka
    excel打开utf-8的csv乱码
    laravel 记录慢sql日志
    php ftp连接的坑
    公用辅助方法
    ubuntu重置网络配置
    php socket
    docker ftp配置多个用户
    php aes-ecb-128位加密
    redis集群 哨兵模式
  • 原文地址:https://www.cnblogs.com/0927wyj/p/5321087.html
Copyright © 2011-2022 走看看