安卓开发学习------1.相对布局(RelativeLayout)实现一个计算器

布局定位函数:
根据父容器:

  • 左对齐:android:layout_alighParentLeft

  • 右对齐:android:layout_alighParentRight

  • 顶端对齐:android:layout_alighParentTop

  • 底部对齐:android:layout_alighParentBottom

  • 水平居中:android:layout_centerHorizontal

  • 垂直居中:android:layout_centerVertical

  • 中央位置:android:layout_centerInParent

根据其他组件:(后加组件id值)

  • 左边:android:layout_toLeftOf

  • 右边:android:layout_toRightOf

  • 上方:android:layout_above

  • 下方:android:layout_below

  • 对齐上边界:android:layout_alignTop

  • 对齐下边界:android:layout_alignBottom

  • 对齐左边界:android:layout_alignLeft

  • 对齐右边界:android:layout_alignRight
    示例

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:textSize="100dp"
        android:textColor="#3CB371"
        android:gravity="right"
        android:text="0"
        android:id="@+id/tv1"
        />
    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="C"
        android:textSize="35dp"

        android:textColor="#ff0000"
        android:layout_below="@id/tv1"
        android:id="@+id/btn_c"
        />
    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="Back"
        android:textSize="20dp"
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值