布局管理的使用——计算器界面设计(LinearLayout,TableLayout,ConstraintLayout三种方式)

题目要求:

分别用布局管理器LinearLayout,TableLayout,ConstraintLayout设计计算器的界面如图所示,基本组件有TextView、Button。通过本次作业,熟悉每种布局管理的特点及适用场景,掌握layout_weight的方法和使用。
在这里插入图片描述

一. LinearLayout

首先,我们需要明白LinearLayout布局的意思。这是一个线性布局。属性有水平或者竖直。接下来,开始完成任务。
第一步,先建一个LinearLayout。在res/layout/下新建一个calumniate_LinearLayout.xml的布局文件。(操作步骤为右击res目录下的layout,选择new Resource File,这里要注意把Root element修改为LinearLayout)
第二步,先加入代码:android:orientation=“vertical”,设置我们的线性布局是垂直方向的。
这是线性布局必须要设置的!!!
第三步,先设置“0”的显示,加入一个TextView, android:layout_width=“match_parent”
android:layout_height=“0dp”
android:layout_weight=“0.229”
android:gravity=“right|bottom”
android:text=“0”
android:textSize=“65dp”
第四步,开始写下面的7行布局,因为结构都是一样的,这里我就写第一行,剩下的自行修改即可。具体为先嵌套一个LinearLayout,然后加入Button按钮,设置权重以及显示的内容,代码如下:
<按钮
android:layout_width=“0dp”
android:layout_height=“match_parent”
android:layout_marginLeft=“3dp”
android:layout_marginBottom=“1dp”
android:layout_weight=“0.167”
android:text=“MC” />
注:按钮就是Button,因为CSDN不好打出来。
第五步,按照上面的步骤继续写6个LinearLayout就好了。

全部代码如下:

// LinearLayout布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#C0C0C0">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.229"
        android:gravity="right|bottom"
        android:text="0"
        android:textSize="65dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.073">

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="3dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.167"
            android:text="MC" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.167"
            android:text="MR" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.167"
            android:text="M+" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.167"
            android:text="M-" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.167"
            android:text="MS" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="3dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.167"
            android:text="M*" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.116">

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="3dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="%" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="√" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="x²" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginRight="3dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="1/x" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.116">

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="3dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="CE" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="C" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="×" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginRight="3dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="÷" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.116">

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="3dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="7" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="8" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="9" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginRight="3dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="X" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.116">

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="3dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="4" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="5" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="6" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginRight="3dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="-" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.116">

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="3dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="1" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="2" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="3" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginRight="3dp"
            android:layout_marginBottom="1dp"
            android:layout_weight="0.25"
            android:text="+" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.116">

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="3dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="3dp"
            android:layout_weight="0.25"
            android:text="±" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="3dp"
            android:layout_weight="0.25"
            android:text="0" />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginBottom="3dp"
            android:layout_weight="0.25"
            android:text="." />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="1dp"
            android:layout_marginRight="3dp"
            android:layout_marginBottom="3dp"
            android:layout_weight="0.25"
            android:text="=" />
    </LinearLayout>
</LinearLayout>

二.TableLayout

这里也是同理,先设置TableLayout的xml文件,然后开始完成任务。
这里我们需要注意的是:一个TableRow代表一行。
其他的原理同LinearLayout。
全部代码如下:

// TableLayout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#C0C0C0">

    <TableRow
        android:layout_height="0dp"
        android:layout_weight="3.55">

        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:gravity="right|bottom"
            android:text="0"
            android:textSize="50dp" />
    </TableRow>

    <TableRow
        android:layout_height="0dp"
        android:layout_weight="1">

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="MC" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="MR" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="M+" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="M-" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="MS" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="M*" />
    </TableRow>

    <TableRow
        android:layout_height="0dp"
        android:layout_weight="1.66">

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="%" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="√" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="x²" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="1/x" />
    </TableRow>

    <TableRow
        android:layout_height="0dp"
        android:layout_weight="1.66">

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="CE" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="C" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="×" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="÷" />
    </TableRow>

    <TableRow
        android:layout_height="0dp"
        android:layout_weight="1.66">

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="7" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="8" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="9" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="X" />
    </TableRow>

    <TableRow
        android:layout_height="0dp"
        android:layout_weight="1.66">

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="4" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="5" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="6" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="-" />
    </TableRow>

    <TableRow
        android:layout_height="0dp"
        android:layout_weight="1.66">

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="1" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="2" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="3" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="+" />
    </TableRow>

    <TableRow
        android:layout_height="0dp"
        android:layout_weight="1.66">

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"

            android:text="±" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="0" />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="." />

        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="=" />
    </TableRow>

</TableLayout>

三.ConstraintLayout

这个约束布局就是比较简单了,可以直接在布局文件里面通过拉动组件来拉出来。
全部代码如下:

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


    <Button
        android:id="@+id/button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="136dp"
        android:text="MC"
        app:layout_constraintEnd_toStartOf="@+id/button2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="MR"
        app:layout_constraintEnd_toStartOf="@+id/button3"
        app:layout_constraintStart_toEndOf="@+id/button"
        app:layout_constraintTop_toTopOf="@+id/button" />

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="M+"
        app:layout_constraintEnd_toStartOf="@+id/button4"
        app:layout_constraintStart_toEndOf="@+id/button2"
        app:layout_constraintTop_toTopOf="@+id/button" />

    <Button
        android:id="@+id/button4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="M-"
        app:layout_constraintEnd_toStartOf="@+id/button5"
        app:layout_constraintStart_toEndOf="@+id/button3"
        app:layout_constraintTop_toTopOf="@+id/button3" />

    <Button
        android:id="@+id/button5"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="MS"
        app:layout_constraintEnd_toEndOf="@+id/button6"
        app:layout_constraintStart_toEndOf="@+id/button4"
        app:layout_constraintTop_toTopOf="@+id/button4" />

    <Button
        android:id="@+id/button6"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="M*"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button5"
        app:layout_constraintTop_toTopOf="@+id/button5" />

    <Button
        android:id="@+id/button7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="%"
        app:layout_constraintBottom_toTopOf="@+id/button15"
        app:layout_constraintEnd_toStartOf="@+id/button8"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button"
        app:layout_constraintVertical_bias="0.77" />

    <Button
        android:id="@+id/button8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="√"
        app:layout_constraintEnd_toStartOf="@+id/button9"
        app:layout_constraintStart_toEndOf="@+id/button7"
        app:layout_constraintTop_toTopOf="@+id/button7" />

    <Button
        android:id="@+id/button9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="x²"
        app:layout_constraintEnd_toStartOf="@+id/button10"
        app:layout_constraintStart_toEndOf="@+id/button8"
        app:layout_constraintTop_toTopOf="@+id/button8" />

    <Button
        android:id="@+id/button10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1/x"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button9"
        app:layout_constraintTop_toTopOf="@+id/button9" />

    <Button
        android:id="@+id/button15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CE"
        app:layout_constraintBottom_toTopOf="@+id/button19"
        app:layout_constraintEnd_toStartOf="@+id/button16"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button7" />

    <Button
        android:id="@+id/button16"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="C"
        app:layout_constraintEnd_toStartOf="@+id/button17"
        app:layout_constraintStart_toEndOf="@+id/button15"
        app:layout_constraintTop_toTopOf="@+id/button15" />

    <Button
        android:id="@+id/button17"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="×"
        app:layout_constraintEnd_toStartOf="@+id/button18"
        app:layout_constraintStart_toEndOf="@+id/button16"
        app:layout_constraintTop_toTopOf="@+id/button16" />

    <Button
        android:id="@+id/button18"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="÷"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button17"
        app:layout_constraintTop_toTopOf="@+id/button17" />

    <Button
        android:id="@+id/button19"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="7"
        app:layout_constraintBottom_toTopOf="@+id/button23"
        app:layout_constraintEnd_toStartOf="@+id/button20"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button15" />

    <Button
        android:id="@+id/button20"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="8"
        app:layout_constraintEnd_toStartOf="@+id/button21"
        app:layout_constraintStart_toEndOf="@+id/button19"
        app:layout_constraintTop_toTopOf="@+id/button19" />

    <Button
        android:id="@+id/button21"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="9"
        app:layout_constraintEnd_toStartOf="@+id/button22"
        app:layout_constraintStart_toEndOf="@+id/button20"
        app:layout_constraintTop_toTopOf="@+id/button20" />

    <Button
        android:id="@+id/button22"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="X"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button21"
        app:layout_constraintTop_toTopOf="@+id/button21" />

    <Button
        android:id="@+id/button23"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="4"
        app:layout_constraintBottom_toTopOf="@+id/button32"
        app:layout_constraintEnd_toStartOf="@+id/button29"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button19" />

    <Button
        android:id="@+id/button29"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="5"
        app:layout_constraintEnd_toStartOf="@+id/button30"
        app:layout_constraintStart_toEndOf="@+id/button23"
        app:layout_constraintTop_toTopOf="@+id/button23" />

    <Button
        android:id="@+id/button31"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="6"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button30"
        app:layout_constraintTop_toTopOf="@+id/button30" />

    <Button
        android:id="@+id/button30"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="-"
        app:layout_constraintEnd_toStartOf="@+id/button31"
        app:layout_constraintStart_toEndOf="@+id/button29"
        app:layout_constraintTop_toTopOf="@+id/button29" />

    <Button
        android:id="@+id/button32"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1"
        app:layout_constraintBottom_toTopOf="@+id/button36"
        app:layout_constraintEnd_toStartOf="@+id/button33"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button23" />

    <Button
        android:id="@+id/button33"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2"
        app:layout_constraintEnd_toStartOf="@+id/button34"
        app:layout_constraintStart_toEndOf="@+id/button32"
        app:layout_constraintTop_toTopOf="@+id/button32" />

    <Button
        android:id="@+id/button34"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="3"
        app:layout_constraintEnd_toStartOf="@+id/button35"
        app:layout_constraintStart_toEndOf="@+id/button33"
        app:layout_constraintTop_toTopOf="@+id/button33" />

    <Button
        android:id="@+id/button35"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="+"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button34"
        app:layout_constraintTop_toTopOf="@+id/button34" />

    <Button
        android:id="@+id/button36"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="±"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/button37"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button32" />

    <Button
        android:id="@+id/button37"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="0"
        app:layout_constraintEnd_toStartOf="@+id/button38"
        app:layout_constraintStart_toEndOf="@+id/button36"
        app:layout_constraintTop_toTopOf="@+id/button36" />

    <Button
        android:id="@+id/button38"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="."
        app:layout_constraintEnd_toStartOf="@+id/button39"
        app:layout_constraintStart_toEndOf="@+id/button37"
        app:layout_constraintTop_toTopOf="@+id/button37" />

    <Button
        android:id="@+id/button39"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="="
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button38"
        app:layout_constraintTop_toTopOf="@+id/button38" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="361dp"
        android:layout_height="134dp"
        android:gravity="right|bottom"
        android:text="0"
        android:textSize="50dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

说明

该文章仅供大家学习交流使用,如有哪里不妥,请大家批评指正。
对代码有哪里不理解的,可以留言评论,不定时回复!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值