android界面的设计(混合嵌套布局)----------计算器界面(学习笔记3)

掌握TextView、Button组件的常用属性和使用方法。
我们先来看一下初始界面和我们要实现的目标界面的对比:
在这里插入图片描述在这里插入图片描述在这里我们要实现按钮button的布局,并且设置button和上面的显示行的文本;
这里呢,需要创建一个新的layout下的xml布局文件;calc.xml;需要了解一下TextView的相关知识。如图所示;在这里插入图片描述

<TextView//设置字体
        android:id="@+id/textResult"
        android:layout_width="match_parent"//文字框的宽度match_parent表示文字框的宽度继承父类的宽度;
        android:layout_height="wrap_content"//文字框的高度wrap_content表示文字框的高度为按照文字大小而设定的高度
        android:gravity="right"//设置文字居右显示
        android:textSize="25sp"//设置文字大小
        android:text="显示结果" />//设置文本内容

然后在布局文件的Design界面创建一个布局在calc布局界面内。
在这里插入图片描述
介绍linearlayout的相关知识;
在这里插入图片描述

<LinearLayout//应用linearlayout布局
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


        <Button
            android:id="@+id/btnC"//设置按钮名称为C(后续的计算器功能设计会用到)
            android:layout_width="0sp"//设置按钮宽度为0
            android:layout_height="wrap_content"//设置按钮高度为字体高
            android:layout_weight="1"//****这个是设置按钮在显示时的比例大小,此处设置为占比1/4
            android:text="C" />//设置按钮上的显示

        <Button
            android:id="@+id/btnDel"
            android:layout_width="0sp"
            android:layout_weight="2"//此处设置为占比2/4
            android:layout_height="wrap_content"
            android:text="Del" />
         <Button
            android:id="@+id/btnDev"
            android:layout_width="0sp"
            android:layout_weight="1"//此处设置为占比1/4
            android:layout_height="wrap_content"
            android:text="÷" />

    </LinearLayout>

后续四行也是按照这样的方法,可以得到最后结果如下:
在这里插入图片描述
到此本届笔记就完成了!!!!
嘿嘿,冲冲冲!!!

发布了5 篇原创文章 · 获赞 0 · 访问量 158

猜你喜欢

转载自blog.csdn.net/qq_40953864/article/details/104462963
今日推荐