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

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

## 请设计下面的三种计算器的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;

   }

}

```

### 总结:

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




目录
相关文章
|
5天前
|
安全 Java Android开发
安卓开发中的新趋势:Kotlin与Jetpack的完美结合
【6月更文挑战第20天】在不断进化的移动应用开发领域,Android平台以其开放性和灵活性赢得了全球开发者的青睐。然而,随着技术的迭代,传统Java语言在Android开发中逐渐显露出局限性。Kotlin,一种现代的静态类型编程语言,以其简洁、安全和高效的特性成为了Android开发中的新宠。同时,Jetpack作为一套支持库、工具和指南,旨在帮助开发者更快地打造优秀的Android应用。本文将探讨Kotlin与Jetpack如何共同推动Android开发进入一个新的时代,以及这对开发者意味着什么。
|
1天前
|
编解码 Android开发 iOS开发
深入探索Android与iOS开发的差异与挑战
【6月更文挑战第24天】在移动应用开发的广阔舞台上,Android和iOS两大操作系统扮演着主角。它们各自拥有独特的开发环境、工具集、用户基础及市场策略。本文将深度剖析这两个平台的开发差异,并探讨开发者面临的挑战,旨在为即将踏入或已在移动开发领域奋斗的开发者提供一份实用指南。
18 13
|
3天前
|
XML Java 开发工具
Android Studio开发Android TV
【6月更文挑战第19天】
|
6天前
|
存储 Java 数据库连接
Android Java开发异步
【6月更文挑战第15天】
|
4天前
|
Java 开发工具 Android开发
安卓与iOS开发差异解析
【6月更文挑战第21天】本文旨在深入探讨安卓和iOS两大移动操作系统在应用开发过程中的主要差异。通过对比分析,揭示各自的设计哲学、编程语言选择、用户界面构建、性能优化策略以及发布流程的异同。文章将提供开发者视角下的实用信息,帮助他们更好地理解各自平台的特点和挑战,从而做出更明智的开发决策。
|
5天前
|
Java 开发工具 Android开发
探索安卓与iOS开发的核心差异
【6月更文挑战第20天】在移动应用开发的广阔天地中,安卓和iOS两大平台各自占据半壁江山。本文将深入探讨这两大操作系统在开发过程中的主要区别,包括编程语言、开发工具、用户界面设计哲学、系统架构以及市场分布等方面。通过对这些关键差异的分析,旨在为开发者提供一份实用的指南,帮助他们在面对项目决策时,能够更加明智地选择合适的平台,并针对特定平台优化他们的应用。
|
5天前
|
开发工具 Android开发 iOS开发
探索安卓与iOS开发的差异:从工具到用户体验
【6月更文挑战第20天】在移动应用开发的广阔天地中,安卓和iOS两大平台各自占据半壁江山。本文将深入探讨这两个操作系统在开发环境、编程语言、用户界面设计以及性能优化等方面的关键差异。我们将通过比较分析,揭示各自平台的独特优势和面临的挑战,为开发者提供决策参考,并为最终用户提供更深层次的用户体验洞察。
|
1天前
|
Java 开发工具 Android开发
探索Android与iOS开发的差异:平台选择对项目成功的影响
在移动应用开发的广阔天地中,Android和iOS两大平台各自占据着半壁江山。本文将深入探讨这两个平台在开发过程中的关键差异点,包括编程语言、开发工具、用户界面设计、性能优化以及市场覆盖等方面。通过对这些关键因素的比较分析,旨在为开发者提供一个清晰的指南,帮助他们根据项目需求和目标受众做出明智的平台选择。
|
5天前
|
Android开发
Android Gradle开发—脚本实现自动打包后复制一份APK文件,并修改APK名称,到指定目录作备份
Android Gradle开发—脚本实现自动打包后复制一份APK文件,并修改APK名称,到指定目录作备份
13 0
|
5天前
|
安全 Android开发 iOS开发
探索安卓与iOS开发的差异:平台特性与用户体验的对比分析
移动应用开发的两大阵营——安卓与iOS,各自拥有独特的开发环境、用户群体和市场定位。本文将深入探讨这两个操作系统在应用开发过程中的主要差异,包括编程语言、开发工具、用户界面设计、性能优化、安全性考量以及发布流程等方面。通过比较分析,旨在为开发者提供跨平台开发的见解和策略,以优化应用性能和提升用户体验。
9 0