3.2.2 RelativeLayout(相对布局)

3.2.2 RelativeLayout(相对布局)

标签: StudyNote


本文声明
本文由Coder-pig编写,想了解其他内容,可见CoderPig’s Android Study Note——目录
尊重作者劳动成果,未经本人授权,禁止转载!违者必究!
目录源地址:http://blog.csdn.net/coder_pig/article/details/51348769


1.相关属性:


2.根据父容器定位与兄弟组件定位:

兄弟组件是处于同一层次容器的控件,比如组件1,2;另外根据兄弟组件定位的属性,
如果参考的对象不是兄弟组件,是会报错的,比如:组件3设置:
android:layout_toLeftOf=”组件1”,就不行啦。


3.margin与padding的区别

区分下:
margin代表的是偏移,比如marginLeft=”5dp”,表示组件离容器左边缘偏移5dp;
padding代表的则是填充,而填充的对象针对的是组件中的元素,比如TextView中的文字
比如为TextView设置paddingLeft=”5dp”,则是在组件里的元素的左边填充5dp的空间
margin针对的是容器中的组件,而padding针对的是组件中的元素,要区分开来!

还有一点很容易被遗忘的是:margin可以设置成负数!比如下面这种进入弹广告的页面,
右上角的退出按钮的定位就可以用到负数的margin

简单的布局示例代码如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context="com.jay.example.relativelayoutdemo.MainActivity"   
    android:background="#00CCCCFF">  

    <ImageView  
        android:id="@+id/img_back"  
        android:layout_width="200dp"  
        android:layout_height="200dp"  
        android:layout_centerInParent="true"  
        android:background="@drawable/myicon" />  

    <ImageView  
        android:id="@+id/img_cancle"  
        android:layout_width="28dp"  
        android:layout_height="28dp"  
        android:layout_alignRight="@id/img_back"  
        android:layout_alignTop="@id/img_back"  
        android:background="@drawable/cancel"  
        android:layout_marginTop="-15dp"  
        android:layout_marginRight="-10dp" />  

</RelativeLayout>  

常用的大概就这些,觉得有遗漏的欢迎反馈,谢谢~


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值