简单的RelativeLayout布局使用

难过记忆力随年龄减退了,干脆一些小知识点,也记录下来。


<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"
    android:padding="10dp"
    tools:context=".MainActivity" >
    <!-- android:padding此处定义整个布局和Activity四周距离,和网页的padding类同 
    -->
    
    <!-- layout_marginTop 组件距离布局顶部距离 dp是单位  layout_toLeftOf组件左边缘
    	对齐靠近指定id的组件。
    -->
     <TextView
         android:id="@+id/user"
         android:layout_marginTop="15dp"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textSize="20dp"
         android:layout_toLeftOf="@+id/passtext"
         android:text="用户:" />

     <!-- layout_toRightOf组件右边缘靠近指定id的组件左边缘 
     	layout_alignBottom 组件底部和指定id的组件底部对齐
     -->
     <EditText
         android:id="@+id/usertext"
         android:layout_toRightOf="@id/user"
         android:layout_alignBottom="@id/user"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="username"
         />
     
     <!--
     	layout_alignBottom 组件底部和指定id的组件底部对齐
     -->
    <TextView
        android:id="@+id/pass"
        android:layout_alignBottom="@id/passtext"
        android:textSize="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="密码:"
        />

     <!-- layout_toRightOf组件右边缘靠近指定id的组件左边缘 
     	layout_below 组件处于指定id的组件下部
     -->
     <EditText
         android:id="@+id/passtext"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_below="@id/usertext"
         android:layout_toRightOf="@id/pass"
         android:text="password" />

     <!-- layout_alignParentRight 组件和父布局右边靠近对齐
     	layout_below 位于指定id组件下部
     -->
      <Button
         android:id="@+id/cancel"
         android:text="cancel"
         android:layout_alignParentRight="true"
         android:layout_below="@id/passtext"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         ></Button>
      
      <!-- layout_toLeftOf 组件左边缘和指定id组件右边缘靠近对齐
     	layout_below 位于指定id组件下部
     -->
     <Button
         android:id="@+id/ok"
         android:text="ok"
         android:layout_toLeftOf="@id/cancel"
         android:layout_below="@id/passtext"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         ></Button>
</RelativeLayout>

布局效果图:


  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值