Study Jams_RelativeLayout

Google Study Jams 活动官方网站http://www.studyjamscn.com/portal.php
这里写图片描述

RelativaLayout

RelativaLayout也被称为相对视图,顾名思义他个可以通过相对定位的方式让控件出现在布局的任意位置。
我将RelativaLayout的属性分成两大类进行介绍,第一类是相对于父视图的属性,第二类是相对于其他控件的属性。
先来说相对于父视图的属性

android:Layout_alignParent+方向=“true”

这里写图片描述
由图中我们可以看到相对于父视图的四个方向的单词。当你想让控件相对于父视图在什么位置时,就将该相对父视图的方向的属性设置为true
例:设置一个TextView控件在父视图的下方,那么代码

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="study Jams"
        android:layout_alignParentBottom="true"/>

其他方向都是一样的,如在左侧就是android:layout_alignParentLeft=”true”
也可以类比出如果要设置控件在左下角

android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"

还有两条属性可以设置控件的居中,也是常用的属性

android:layout_centerHorizontal="true"
//水平居中
android:layout_centerVertical="true"
//垂直居中

下来介绍相对于控件位置的属性,为以下四种属性
android:layout_above=之后为作为参照物的空间

android:layout_above="@+id/textview"
//该控件在id为textview控件的上方
android:layout_below="@+id/textview"
//该控件在id为textview控件的下方
android:layout_toLeftOf="@+id/textview"
//该控件在id为textview控件的左侧
android:layout_toRightOf="@+id/textview"
//该控件在id为textview控件的右侧

例如如下代码设置内容为Google的TextView位于内容为Study Jams的TextView下发

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#f00"
        android:text="Google"
        android:textSize="22sp"
        android:layout_below="@id/textview"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="study Jams"
        android:background="#0f0"
        android:textSize="22sp"
        android:id="@+id/textview"
        />
</RelativeLayout>


这里写图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Maybe_ch

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值