Android移动终端设计实验一+基本组件应用实验
实验1:基本组件应用实验
一、 实验目的 本次实验的目的是让大家熟悉Android开发中的UI设计,包括了解和熟悉常用控件的使用、界面布局、ArrayAdapter和SimpleAdapter适配器的基本用法。
|
二、 实验环境 Windows7 Eclipse MARS.2 AVD虚拟机 |
三、实验内容及结果 题目1:四种界面布局分别使用LinearLayout、RelativeLayout、TableLayout和AbsoluteLayout四种布局设计登录窗口,界面如下图所示。 题目代码: LinearLayout 实现 MainActivity.java <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <TextView android:id="@+id/user" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名:" /> <EditText android:id="@+id/username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="please input your username"/>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/pass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码:" /> <EditText android:id="@+id/password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="please input your password"/>
</LinearLayout> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="login">
</Button>
</LinearLayout>
RelativeLayout 实现 MainActivity.java <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" >
<TextView android:id="@+id/user" android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名:" /> <EditText android:id="@+id/username" android:layout_toRightOf="@+id/user" android:layout_alignBaseline="@+id/user" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="input username" ></EditText> <TextView android:id="@+id/pass" android:layout_below="@+id/user" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码:" ></TextView> |