承接日志一,在新建的项目中设计一个简单的界面
最终效果图
首先打开已经创建好的activity_main.xml文件
在页面上写代码,我用的是基础的LinearLayout,并嵌套使用,使得界面横竖有序,更为好看
<?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" >//竖列
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/hello"/> <!--strings.xml文件中设置-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">横列
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">//嵌套竖列
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="@string/name"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="@string/sex"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/age"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/edit1"
android:inputType="text"
android:textSize="8dp"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/boy01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boy" />
<RadioButton
android:id="@+id/girl01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/girl" />
</RadioGroup>
</LinearLayout>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/edit2"
android:inputType="text"
android:textSize="11dp"
/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/hobby"
/>
<CheckBox
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/check1"
android:textSize="20sp"
android:text="@string/basketball"
/>
<CheckBox
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/check2"
android:textSize="20sp"
android:text="@string/football"
/>
<CheckBox
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/check3"
android:textSize="20sp"
android:text="@string/music"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ok"
android:text="@string/ok"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/message"
android:text=""
/>
</LinearLayout>
完成后如下图所示
会看到界面上没有显示所要的文字,这是因为还要在strings.xml设置name(这样做是为了以后管理更简洁,而且切换语言版本也更方便)
打开strings.xml,设置想要改的名称
<resources>
<string name="app_name">test</string>
<string name="hello">学生信息录入</string> //“学生信息录入”就是要改的名字
<string name="name">姓名:</string>
<string name="sex">性别:</string>
<string name="age">年龄:</string>
<string name="hobby">业余爱好</string>
<string name="boy">男</string>
<string name="girl">女</string>
<string name="basketball">篮球</string>
<string name="football">足球</string>
<string name="music">音乐</string>
<string name="ok">确定</string>
</resources>
然后运行,即可完成一个简单的界面
(偷懒没有写按钮监听代码)