线性布局小实现——计算器的简单布局

本文介绍了如何使用线性布局(LinearLayout)实现计算器的界面布局。首先采用一个垂直方向的LinearLayout,内部包含一个相对布局和另一个垂直LinearLayout。相对布局中设置控件,并探讨了控件属性对布局的影响。接着在下层LinearLayout中添加多个Button。作者强调LinearLayout的垂直和平行属性,理解这一点对布局至关重要。在布局过程中遇到的问题和解决方法也进行了分享,提倡动手实践和尝试不同布局以优化代码和提高效率。
摘要由CSDN通过智能技术生成

本来是想用相对布局来写计算器的布局,然后莫名其妙的变成了线性布局,心塞。

  • 上代码
<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_height="10dp"
        android:layout_width="match_parent"
        android:layout_weight="0.4">

        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="Calculate布局实现"
            android:textColor="#1FC8F8"
            android:id="@+id/mainTextView1"
            android:textSize="17sp"/>

        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:hint="请输入计算"
            android:textSize="40sp"
            android:text="计算输出口"/>

    </RelativeLayout>

    <TextView
        android:layout_height="1dp"
        android:layout_width="match_parent"
        android:background="#000000"/>

    <LinearLayout
        android:layout_height="40dp"
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_weight="2">

        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:layout_weight="1.0"
            android:gravity="center"
            andro
  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值