安卓开发学习之设计三种计算机界面【A篇】
        【摘要】  请设计下面的三种计算器的UI: 为了更好的在三个界面之间跳转,添加一个主界面。 activity_main.xml 界面效果: 简单计算器: chengxujishuanqi.xml 界面效果: 科学计算器: kexuejishuanqi.xml 界面效果: 请设计下面的三种计算器的UI:1.简单的计算器2.科学计算器3.程序计算器不用实现具体功能,只需设计界面即可! 为了更好的在三个界面...
    
    
    
    请设计下面的三种计算器的UI:
1.简单的计算器
 
2.科学计算器
 
3.程序计算器
 
 不用实现具体功能,只需设计界面即可!
为了更好的在三个界面之间跳转,添加一个主界面。
activity_main.xml
线性布局中添加4个按钮
<?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"
    tools:context=".MainActivity">
    <LinearLayout
        android:layout_width="431dp"
        android:layout_height="669dp"
        android:orientation="vertical"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="-4dp"
        tools:layout_editor_absoluteY="57dp">
        <Button
            android:id="@+id/button21"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="简单计算器" />
        <Button
            android:id="@+id/button22"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="科学计算器" />
        <Button
            android:id="@+id/button23"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="程序计算器" />
        <Button
            android:id="@+id/button24"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="退出" />
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
界面效果:

简单计算器:
chengxujishuanqi.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="7">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center|right"
            android:text="0"
            android:textSize="50sp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_weight="1"
        android:weightSum="4">
        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="退格"
            android:textSize="30sp" />
        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="清除"
            android:textSize="30sp" />
        <Button
            android:id="@+id/button3"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="±"
            android:textSize="40sp" />
        <Button
            android:id="@+id/button4"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="+"
            android:textSize="40sp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:weightSum="4">
        <Button
            android:id="@+id/button5"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="7"
            android:textSize="40sp" />
        <Button
            android:id="@+id/button6"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="8"
            android:textSize="40sp" />
        <Button
            android:id="@+id/button7"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="9"
            android:textSize="40sp" />
        <Button
            android:id="@+id/button8"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="—"
            android:textSize="40sp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:weightSum="4">
        <Button
            android:id="@+id/button9"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="4"
            android:textSize="40sp"/>
        <Button
            android:id="@+id/button10"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="5"
            android:textSize="40sp"/>
        <Button
            android:id="@+id/button11"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="6"
            android:textSize="40sp"/>
        <Button
            android:id="@+id/button12"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="*"
            android:textSize="40sp"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:weightSum="4">
        <Button
            android:id="@+id/button13"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="1"
            android:textSize="40sp"/>
        <Button
            android:id="@+id/button14"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="2"
            android:textSize="40sp"/>
        <Button
            android:id="@+id/button15"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="3"
            android:textSize="40sp"/>
        <Button
            android:id="@+id/button16"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="/"
            android:textSize="40sp"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:weightSum="4">
        <Button
            android:id="@+id/button17"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="0"
            android:textSize="40sp"/>
        <Button
            android:id="@+id/button18"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="."
            android:textSize="40sp"/>
        <Button
            android:id="@+id/button19"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="1/x"
            android:textSize="30sp"/>
        <Button
            android:id="@+id/button20"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="="
            android:textSize="40sp"/>
    </LinearLayout>
</LinearLayout>
界面效果:

科学计算器:
kexuejishuanqi.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center|right"
            android:text="0"
            android:textSize="50sp"/>
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="21dp"
            android:layout_margin="10dp"
            android:padding="0dp">
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <RadioGroup
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="horizontal">
                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="角度"
                        android:textSize="15dp" />
                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="弧度"
                        android:textSize="15dp" />
                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="梯度"
                        android:textSize="15dp" />
                </RadioGroup>
            </TableRow>
        </TableLayout>
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="215dp">
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="487dp"
                android:layout_weight="1"
                android:padding="0dp">
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="SIN" />
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="COS" />
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="TAN" />
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="COT"></Button>
            </TableRow>
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="487dp"
                android:layout_weight="1"
                android:padding="0dp">
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="ASIN"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="ACOS"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="ATAN"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="ACOT"></Button>
            </TableRow>
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="487dp"
                android:layout_weight="1"
                android:padding="0dp">
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="SINH"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="COSH"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="TANH"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="COTH"></Button>
            </TableRow>
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="487dp"
                android:layout_weight="1"
                android:padding="0dp">
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="ASINH"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="ACOSH"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="ATANH"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="ACOTH"></Button>
            </TableRow>
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="487dp"
                android:layout_weight="1"
                android:padding="0dp">
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="LN"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="LOG10"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="N!"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="X^Y"></Button>
            </TableRow>
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="487dp"
                android:layout_weight="1"
                android:padding="0dp">
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="E^X"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="π"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="("></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text=")"></Button>
            </TableRow>
        </TableLayout>
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="186dp">
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="487dp"
                android:layout_weight="1"
                android:padding="0dp">
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="退格"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="清除"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="±"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="+"></Button>
            </TableRow>
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="487dp"
                android:layout_weight="1"
                android:padding="0dp">
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="7"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="8"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="9"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="-"></Button>
            </TableRow>
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="487dp"
                android:layout_weight="1"
                android:padding="0dp">
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="4"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="5"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="6"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="*"></Button>
            </TableRow>
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="487dp"
                android:layout_weight="1"
                android:padding="0dp">
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="1"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="2"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="3"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="/"></Button>
            </TableRow>
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="487dp"
                android:layout_weight="1"
                android:padding="0dp">
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="0"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="."></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="1/X"></Button>
                <Button
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="="></Button>
            </TableRow>
        </TableLayout>
    </LinearLayout>
</LinearLayout>
界面效果:

            【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
                cloudbbs@huaweicloud.com
                
            
        
        
        
        
        
        
        - 点赞
- 收藏
- 关注作者
 
             
           
评论(0)