阅读 168

Android相对布局(RelativeLayout)

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,运行结果截图

来源:https://www.cnblogs.com/d534/p/14808926.html

服务器评测 http://www.cncsto.com/ 

服务器测评 http://www.cncsto.com/ 


文章分类
后端
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐