创建计算器工程
-
打开Android Studio
-
创建工程-点击上图“New Project”
选择“Empty Activity”,然后点击“Next”
-
设置项目基本信息
可以参考我下面的设置,也可以保持默认设置不变,对于“Save Location”设置一个存放工程的目录即可。
最后点击“Finish”。
4. 成品如下:
res/layout/activity_main.xml
点击右上角“Split”,切换显示模式,这样可以一边看代码,一遍看效果:
下图是我们最终要做出来的计算器的界面。
那如何做呢? 我们一步步来看。
初学者看到这个界面上有这么多东西,可能不知道该怎么下手,所以呢,我们需要化繁为简。简化,简化,再简化。
-
下图我标了红框
整个界面,其实就是由这几个红框像积木一样搭起来的。
-
先把红框里的内容去掉
-
最后把所有的框都去掉
这就是我们的起点线。
res/layout/activity_main.xml
- 删除上面代码,替换成下面代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#EE181818" android:orientation="vertical"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#EE181818" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="120dp">
关注
打赏
