您的位置:首页 > 财经 > 产业 > 厦门seo网络推广_更合公司网站建设_网站整站优化公司_武汉百度快照优化排名

厦门seo网络推广_更合公司网站建设_网站整站优化公司_武汉百度快照优化排名

2024/10/5 22:21:51 来源:https://blog.csdn.net/cxx0316/article/details/142369131  浏览:    关键词:厦门seo网络推广_更合公司网站建设_网站整站优化公司_武汉百度快照优化排名
厦门seo网络推广_更合公司网站建设_网站整站优化公司_武汉百度快照优化排名

1 实验名称

       简单计算器界面

2实验目的

       掌握基本布局管理器的使用方法和基本控件的使用方法,以及事件监听处理的使用方法

3 实验源代码

布局文件代码:

<?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"><EditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="0"android:gravity="right|bottom"android:minLines="2"android:enabled="false"/><GridLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:columnCount="5"><Buttonstyle="@style/btnStyle"android:text="MC"/><Buttonstyle="@style/btnStyle"android:text="MR"/><Buttonstyle="@style/btnStyle"android:text="MS"/><Buttonstyle="@style/btnStyle"android:text="M+"/><Buttonstyle="@style/btnStyle"android:text="M-"/><Buttonstyle="@style/btnStyle"android:text="←"/><Buttonstyle="@style/btnStyle"android:text="CE"/><Buttonstyle="@style/btnStyle"android:text="C"/><Buttonstyle="@style/btnStyle"android:text="±"/><Buttonstyle="@style/btnStyle"android:text="√"/><Buttonstyle="@style/btnStyle"android:text="7"/><Buttonstyle="@style/btnStyle"android:text="8"/><Buttonstyle="@style/btnStyle"android:text="9"/><Buttonstyle="@style/btnStyle"android:text="/"/><Buttonstyle="@style/btnStyle"android:text="%"/><Buttonstyle="@style/btnStyle"android:text="4"/><Buttonstyle="@style/btnStyle"android:text="5"/><Buttonstyle="@style/btnStyle"android:text="6"/><Buttonstyle="@style/btnStyle"android:text="*"/><Buttonstyle="@style/btnStyle"android:text="1/X"/></GridLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/btnOne"style="@style/btnStyle"android:text="1"/><Buttonandroid:id="@+id/btnTwo"style="@style/btnStyle"android:text="2"android:layout_toRightOf="@id/btnOne"/><Buttonandroid:id="@+id/btnThree"style="@style/btnStyle"android:text="3"android:layout_toRightOf="@id/btnTwo"/><Buttonandroid:id="@+id/bar"style="@style/btnStyle"android:text="-"android:layout_toRightOf="@id/btnThree"/><Buttonandroid:id="@+id/btnEqual"android:layout_width="80dp"android:layout_height="122dp"android:text="="android:layout_toRightOf="@id/bar"/><Buttonandroid:id="@+id/btnAdd"style="@style/btnStyle"android:text="+"android:layout_toLeftOf="@id/btnEqual"android:layout_alignBottom="@+id/btnEqual"/><Buttonandroid:id="@+id/btnDot"style="@style/btnStyle"android:text="+"android:layout_toLeftOf="@id/btnAdd"android:layout_alignBottom="@+id/btnEqual"/><Buttonandroid:layout_width="162dp"android:layout_height="60dp"android:text="0"android:layout_toLeftOf="@id/btnDot"android:layout_alignBottom="@id/btnEqual"/></RelativeLayout>
</LinearLayout>

java代码:

package com.example.linearlayoutdemo;import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);EdgeToEdge.enable(this);setContentView(R.layout.activity_main);ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);return insets;});}
}

4 实验运行结果图

5 实验总结

       在calculator.xml布局文件中对计算器的整体进行布局,包括一个文本编辑框、十个数字按钮以及一些功能按钮。

       在写布局文件的过程中,一些功能键名称无法从键盘上直接输入,要从别的地方复制粘贴过来才行。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com