zoukankan      html  css  js  c++  java
  • Android相对布局(RelativeLayout)

    1,编写xml代码

    <?xml version="1.0" encoding="utf-8"?>
    <!--
    相对布局RelativeLayout
    -->
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ImageView
            android:id="@+id/img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/img3"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮"
            android:textSize="100dp"
    
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="右边1"
            android:textSize="100dp"
            android:textColor="@color/black"
            android:layout_toRightOf="@id/img"
            android:layout_alignTop="@id/img"
            android:layout_centerVertical="true"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="右边2"
            android:textSize="100dp"
            android:textColor="@color/black"
            android:layout_toRightOf="@id/img"
            android:layout_alignBottom="@id/img"
            android:layout_centerVertical="true"/>
    
         <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="上边"
            android:textSize="100dp"
            android:textColor="@color/black"
            android:layout_above="@id/img"
            android:layout_centerHorizontal="true"/>
         <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="下边"
            android:textSize="100dp"
            android:textColor="@color/black"
            android:layout_below="@id/img"
            android:layout_centerHorizontal="true"/>
         <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="左边1"
            android:textSize="100dp"
            android:textColor="@color/black"
            android:layout_toLeftOf="@id/img"
            android:layout_alignTop="@id/img"
            android:layout_centerVertical="true"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="左边2"
            android:textSize="100dp"
            android:textColor="@color/black"
            android:layout_toLeftOf="@id/img"
            android:layout_alignBottom="@id/img"
            android:layout_centerVertical="true"/>
    
    </RelativeLayout>
    

    2,运行结果截图

  • 相关阅读:
    【新特性速递】卡片式表格,Yeah~~~
    6个最佳DevOps播客
    在裸金属服务器Bare Metal上Kubernetes
    保护Java应用程序不被窃取数据和源代码2
    家政服务行业动态
    15个免费数据集数据科学项目
    性能测试工具
    利用Apache Pulsar的实时边缘计算
    软件开发的八个误解
    如何防止范围蔓延
  • 原文地址:https://www.cnblogs.com/d534/p/14808926.html
Copyright © 2011-2022 走看看