安卓开发学习之设计三种计算机界面

简介: 设计三种计算机界面

## 请设计下面的三种计算器的UI:


1.简单的计算器

caculator1.png



2.科学计算器

caculator2.png



3.程序计算器

caculator3.png

不用实现具体功能,只需设计界面即可!

### 为了更好的在三个界面之间跳转,添加一个主界面。

#### activity_main.xml

线性布局中添加4个按钮


```xml

<?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>

```

#### 界面效果:

屏幕截图 2022-04-06 180941.png

### 简单计算器:

#### chengxujishuanqi.xml


```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>

```

#### 界面效果:

屏幕截图 2022-04-06 181648.png




### 科学计算器:

#### kexuejishuanqi.xml


```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>

```


#### 界面效果:

屏幕截图 2022-04-06 181724.png



### 程序计算器:

#### chengxujishuanqi.xml


```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="76dp"

                       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" />


                   <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="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" />


                   <RadioButton

                       android:layout_width="wrap_content"

                       android:layout_height="wrap_content"

                       android:layout_weight="1"

                       android:text="单字节"

                       android:textSize="15dp" />

               </RadioGroup>

           </TableRow>


       </TableLayout>



       <GridLayout

           android:layout_width="match_parent"

           android:layout_height="wrap_content"

           android:columnCount="4"

           android:orientation="horizontal"

           android:rowCount="3">


           <Button

               android:layout_width="102dp"

               android:layout_height="match_parent"

               android:text="NOT"

               android:textColor="#FBF9F9" />


           <Button

               android:layout_width="103dp"

               android:layout_height="match_parent"

               android:text="AND" />


           <Button

               android:layout_width="104dp"

               android:layout_height="match_parent"

               android:text="OR" />


           <Button

               android:layout_width="99dp"

               android:layout_height="match_parent"

               android:text="XOR" />


           <Button

               android:layout_width="104dp"

               android:layout_height="match_parent"

               android:text="循环左移" />


           <Button

               android:layout_width="104dp"

               android:layout_height="match_parent"

               android:text="循环右移" />


           <Button

               android:layout_width="104dp"

               android:layout_height="match_parent"

               android:text="左移" />


           <Button

               android:layout_width="102dp"

               android:layout_height="match_parent"

               android:text="MOD" />


           <Button

               android:layout_columnSpan="2"

               android:layout_gravity="fill"

               android:text="无符号右移" />


           <Button

               android:layout_width="wrap_content"

               android:layout_columnSpan="2"

               android:layout_gravity="fill"

               android:text="有符号右移" />



       </GridLayout>


       <TableLayout

           android:layout_width="match_parent"

           android:layout_height="212dp">


           <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="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="6"></Button>


               <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="+"></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="3"></Button>


               <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="+"></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="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="/"></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="A"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="B"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="C"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="D"></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"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="F"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="G"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="="></Button>



           </TableRow>




       </TableLayout>


   </LinearLayout>


</LinearLayout>

```


#### 界面效果:


屏幕截图 2022-04-06 181747.png





### 主界面和其他界面的交互

点击对应的按钮,跳转相应的界面!

#### MainActivity


```java

package com.example.myapplication;


import androidx.appcompat.app.AppCompatActivity;


import android.content.Intent;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.View;

import android.widget.Button;


public class MainActivity extends AppCompatActivity {


   @Override

   protected void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_main);

       Button btn1=(Button) findViewById(R.id.button21);

       Button btn2=(Button) findViewById(R.id.button22);

       Button btn3=(Button) findViewById(R.id.button23);

       Button btn4=(Button) findViewById(R.id.button24);

       btn1.setOnClickListener(new View.OnClickListener(){

           @Override

           public  void onClick(View View){

               setContentView(R.layout.jiandanjishuanqi);

           }

       });

       btn2.setOnClickListener(new View.OnClickListener(){

           @Override

           public  void onClick(View View){

               setContentView(R.layout.kexuejishuanqi);

           }

       });

       btn3.setOnClickListener(new View.OnClickListener(){

           @Override

           public  void onClick(View View){

               setContentView(R.layout.chengxujishuanqi);

           }

       });

       btn4.setOnClickListener(new View.OnClickListener(){

               @Override

               public  void onClick(View View){

                   System.exit(0);

       }


       });

   }

   @Override

   public  boolean onKeyDown(int keyCode, KeyEvent event){

       if(keyCode==KeyEvent.KEYCODE_BACK){

           Intent intent=new Intent(this,MainActivity.class);

           intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

           startActivity(intent);

       }

       return  true;

   }

}

```

### 总结:

安卓实验作业,刚接触能力有限就做了个大概,可以根据自己的需求添加主题,样式,颜色!




目录
相关文章
|
6天前
|
IDE Android开发 iOS开发
探索Android与iOS开发的差异:平台选择对项目成功的影响
【9月更文挑战第27天】在移动应用开发的世界中,Android和iOS是两个主要的操作系统平台。每个系统都有其独特的开发环境、工具和用户群体。本文将深入探讨这两个平台的关键差异点,并分析这些差异如何影响应用的性能、用户体验和最终的市场表现。通过对比分析,我们将揭示选择正确的开发平台对于确保项目成功的重要作用。
|
5天前
|
Java Maven 开发工具
第一个安卓项目 | 中国象棋demo学习
本文是作者关于其第一个安卓项目——中国象棋demo的学习记录,展示了demo的运行结果、爬坑记录以及参考资料,包括解决Android Studio和maven相关问题的方法。
第一个安卓项目 | 中国象棋demo学习
|
2天前
|
开发框架 移动开发 Android开发
安卓与iOS开发中的跨平台解决方案:Flutter入门
【9月更文挑战第30天】在移动应用开发的广阔舞台上,安卓和iOS两大操作系统各自占据半壁江山。开发者们常常面临着选择:是专注于单一平台深耕细作,还是寻找一种能够横跨两大系统的开发方案?Flutter,作为一种新兴的跨平台UI工具包,正以其现代、响应式的特点赢得开发者的青睐。本文将带你一探究竟,从Flutter的基础概念到实战应用,深入浅出地介绍这一技术的魅力所在。
18 7
|
6天前
|
开发框架 前端开发 Android开发
安卓与iOS开发中的跨平台解决方案
【9月更文挑战第27天】在移动应用开发的广阔天地中,安卓和iOS两大操作系统如同双子星座般耀眼。开发者们在这两大平台上追逐着创新的梦想,却也面临着选择的难题。如何在保持高效的同时,实现跨平台的开发?本文将带你探索跨平台开发的魅力所在,揭示其背后的技术原理,并通过实际案例展示其应用场景。无论你是安卓的忠实拥趸,还是iOS的狂热粉丝,这篇文章都将为你打开一扇通往跨平台开发新世界的大门。
|
3天前
|
缓存 Java Linux
探索安卓开发:从新手到专家的旅程
【9月更文挑战第30天】在这篇文章中,我们将一起踏上一段激动人心的旅程,探索安卓开发的广阔世界。无论你是刚入门的新手,还是希望提升技能的开发者,本文都将为你提供宝贵的知识和指导。我们将深入探讨安卓开发的基础知识、关键概念、实用工具和最佳实践,帮助你在安卓开发领域取得更大的成功。让我们一起开启这段精彩的旅程吧!
|
3天前
|
监控 安全 Java
Kotlin 在公司上网监控中的安卓开发应用
在数字化办公环境中,公司对员工上网行为的监控日益重要。Kotlin 作为一种基于 JVM 的编程语言,具备简洁、安全、高效的特性,已成为安卓开发的首选语言之一。通过网络请求拦截,Kotlin 可实现网址监控、访问时间记录等功能,满足公司上网监控需求。其简洁性有助于快速构建强大的监控应用,并便于后续维护与扩展。因此,Kotlin 在安卓上网监控应用开发中展现出广阔前景。
7 1
|
7天前
|
存储 开发工具 Android开发
使用.NET MAUI开发第一个安卓APP
【9月更文挑战第24天】使用.NET MAUI开发首个安卓APP需完成以下步骤:首先,安装Visual Studio 2022并勾选“.NET Multi-platform App UI development”工作负载;接着,安装Android SDK。然后,创建新项目时选择“.NET Multi-platform App (MAUI)”模板,并仅针对Android平台进行配置。了解项目结构,包括`.csproj`配置文件、`Properties`配置文件夹、平台特定代码及共享代码等。
|
13天前
|
存储 Java Android开发
🔥Android开发大神揭秘:从菜鸟到高手,你的代码为何总是慢人一步?💻
在Android开发中,每位开发者都渴望应用响应迅速、体验流畅。然而,代码执行缓慢却是常见问题。本文将跟随一位大神的脚步,剖析三大典型案例:主线程阻塞导致卡顿、内存泄漏引发性能下降及不合理布局引起的渲染问题,并提供优化方案。通过学习这些技巧,你将能够显著提升应用性能,从新手蜕变为高手。
16 2
|
14天前
|
Java Android开发 C++
🚀Android NDK开发实战!Java与C++混合编程,打造极致性能体验!📊
在Android应用开发中,追求卓越性能是不变的主题。本文介绍如何利用Android NDK(Native Development Kit)结合Java与C++进行混合编程,提升应用性能。从环境搭建到JNI接口设计,再到实战示例,全面展示NDK的优势与应用技巧,助你打造高性能应用。通过具体案例,如计算斐波那契数列,详细讲解Java与C++的协作流程,帮助开发者掌握NDK开发精髓,实现高效计算与硬件交互。
54 1
|
6天前
|
搜索推荐 前端开发 Android开发
安卓开发中的自定义视图:打造个性化用户界面
【9月更文挑战第26天】在移动应用开发的广阔天地中,定制性是提升用户体验的不二法宝。本文将带你深入了解安卓开发中自定义视图的魅力所在,通过简洁明了的语言和直观的代码示例,展示如何从零开始创建属于自己的控件,让你的应用界面与众不同。
下一篇
无影云桌面