Android实训一(从零到入门)

实训一 用户界面设计

一、【实训目的】

(1) 用户界面基础

(2) 常用控件

(3) 提交实训报告和实训源码

二、【实训步骤和要求】

  1. 实现下图所示的用户界面设计。请参考讲义步骤写出程序编写步骤,并列出相应的源代码。

 源项目:

array.xml源程序:

<resources>
<string-array name="user">
<item>0~10</item>
<item>10~20</item>
<item>20~40</item>
<item>40以上</item>
</string-array>
</resources>

activity.xml源程序:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"				//表示该布局的宽度与父容器(屏幕)相同
        android:layout_height="wrap_content" >			//表示该布局的高度恰好能包裹它的内容

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="用户名:" />

        <EditText
            android:id="@+id/etUserName"
            android:layout_width="0dp"					//编辑框与文本框的间距为0
            android:layout_height="wrap_content"
            android:layout_weight="1.0"					//权重占1
            android:hint="请输入用户名" />
    </LinearLayout>
//文本框不需要id,逻辑框需要id
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密码:" />

        <EditText
            android:id="@+id/etUserPass"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:hint="请输入密码"
            android:inputType="textPassword" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="姓名:" />

        <EditText
            android:id="@+id/etRealName"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:hint="请输入真实姓名" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="性别/" />

        <RadioGroup											//单选栏需id
            android:id="@+id/rgSex"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:checkedButton="@+id/rdoMale"			//表示默认选中的按钮是”男”
            android:orientation="horizontal" >				//表示该布局从左到右排序

            <RadioButton
                android:id="@+id/rdoMale"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1.0"
                android:text="男" >
            </RadioButton>

            <RadioButton
                android:id="@+id/rdoFemale"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1.0"
                android:text="女" >
            </RadioButton>
        </RadioGroup>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="年龄:" />

        <Spinner												//Spinner为下拉列表,需要id
            android:id="@+id/user"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0" 
            android:entries="@array/user"/>					//指定列表的项数组
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="爱好:" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <CheckBox											//复选框,需要id
            android:id="@+id/chkRead"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:text="看小说" />

        <CheckBox
            android:id="@+id/chkPlayGame"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:text="玩游戏" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <CheckBox
            android:id="@+id/chkEat"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:text="美食" />

        <CheckBox
            android:id="@+id/chkSleep"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:text="睡觉" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <CheckBox
            android:id="@+id/chkLookFilm"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:text="看电影" />

        <CheckBox
            android:id="@+id/chkMunic"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:text="听音乐" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/btnRegister"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:onClick="doClick"					
//点击按钮时会利用反射的方式调用对应Activity中的click()方法
            android:text="注册" />

        <Button
            android:id="@+id/btnCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:onClick="doClick"
            android:text="取消" />
    </LinearLayout>

</LinearLayout>

项目成果图:

附注:该专栏是博主上学时的实训项目,可供访客练习与参考。代码质量不是很好,但能实现,仅供参考! 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值