简介:
记录了Android开发第一节实验课项目与环境搭建中的困难与解决过程
一、环境搭建
- 需要安装并配置jdk:
由于之前已经学过JAVA相关知识,并用到jdk,所以这一步跳过 - 安装Android Studio:
到官网或者其他可靠渠道下载并安装即可,更新SDK配置 - 下载外部模拟器:
由于AS本身自带的模拟器较大且启动慢,在学习过程中主要采用外部模拟器进行连接运行apk
二、实验一
【关于线性布局的使用】
<!--Layout_register.xml-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@mipmap/cloud">
<!-- 标题-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="64dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Hello World!"
android:textSize="30sp"
android:textStyle="bold" />
</LinearLayout>
<!-- 用户名 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名"
android:textSize="24sp" />
<EditText
android:id="@+id/editTextTextPersonName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="请输入用户名"
android:inputType="textPersonName" />
</LinearLayout>
<!--账号 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="72dp"
android:layout_height="wrap_content"
android:text="账号"
android:textSize="24sp" />
<EditText
android:id="@+id/editID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="请输入您的数字账号" />
</LinearLayout>
<!--密码 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="72dp"
android:layout_height="wrap_content"
android:text="密码"
android:textSize="24sp" />
<EditText
android:id="@+id/editTextTextPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="请输入您的密码" />
</LinearLayout>
<!--性别--><!--一个文字框+一组两个的单选按钮,水平排列-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/sex"
android:layout_width="69dp"
android:layout_height="match_parent"
android:text="性别"
android:textSize="24sp" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/radioButton8"
android:layout_width="116dp"
android:layout_height="wrap_content"
android:checked="true"
android:text="女"/>
<RadioButton
android:id="@+id/radioButton6"
android:layout_width="99dp"
android:layout_height="wrap_content"
android:text="男" />
</RadioGroup>
</LinearLayout>
<!--年龄-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView"
android:layout_width="69dp"
android:layout_height="45dp"
android:text="年龄"
android:textSize="24sp" />
<Spinner
android:layout_width="180dp"
android:layout_height="match_parent"
android:entries="@array/age"/>
</LinearLayout>
<!--爱好-->
<!--三个垂直排列,其中两个水平排列-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="202dp"
android:orientation="vertical">
<TextView
android:id="@+id/favor"
android:layout_width="match_parent"
android:layout_height="42dp"
android:text="爱好"
android:textSize="24sp" />
<!--第一个水平排列-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="203dp"
android:layout_height="wrap_content"
android:text="吃饭" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="207dp"
android:layout_height="wrap_content"
android:checked="true"
android:text="睡觉" />
</LinearLayout>
<!--第二个水平排列-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="202dp"
android:layout_height="wrap_content"
android:text="打豆豆" />
<CheckBox
android:id="@+id/checkBox4"
android:layout_width="216dp"
android:layout_height="wrap_content"
android:text="上网" />
</LinearLayout>
</LinearLayout>
<!--操作按钮-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#484242"
android:text="注册" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#584646"
android:text="返回" />
</LinearLayout>
</LinearLayout>
<!--values文件下age.xml-->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="age">
<item >18-28</item>
<item >29-39</item>
<item >40-50</item>
<item >51-61</item>
</string-array>
</resources>
【效果图】
实验教训:
1.不要盲目自信,课前没有认真的学习老师给的文档和相关视频,自己捣鼓了两天才好不容易解决的问题,最后才发现老师给的资料里早就详细解释了;
2.编程过程中,要仔细要耐心,写成对标签时,注意“/”的用法,一开始因为不小心在非结束语句加了一个“/”,导致最后的标签添加后显示错误;
3.世上无难事,只怕有心人!