相对布局(RelativeLayout)

RelativeLayout中往往需要定义每一个控件的资源ID

layout_toLeftOf      layout_toRightOf    layout_below表示相对位置

layout_alignXXX表示对齐方式

layout_marginXXX表示间距

android:layout_centerInParent="true":将控件放置于父界面的中心位置

即子控件的位置可以取决于兄弟控件或者父控件的位置,与LinearLayout相比,减少嵌套使用,界面代码简洁.


实例代码 : (下列代码效果是由以中间的控件为参照物来定位的)

<?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">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Java"
        android:layout_centerInParent="true"
        android:textSize="30sp"
        android:textColor="#F000"
        android:id="@+id/textView_center" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="左上"
        android:textSize="30sp"
        android:id="@+id/textView_left_top"
        android:layout_above="@+id/textView_center"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="60dp"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="右上"
        android:textSize="30sp"
        android:id="@+id/textView_right_top"
        android:layout_alignTop="@+id/textView_left_top"
        android:layout_alignParentEnd="true" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="左下"
  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值