学习小结

通过四周的安卓的学习,也或多或少的了解了一些安卓的知识,现在就前面四周的学习内容进行如下总结: Android是基于Linux内核,开放源码的操作系统,主要应用于便携设备,如智能手机,平板电脑等.

一.界面设计

1.1.1 界面控件的基本结构

1.1常用的界面控件:
1.TextView(显示文本信息) 2.Button(普通按钮) 3.EditText(可编辑的文本框组件/输入框) 4.ImageView(用于显示图片) 5.ImageButton(图片按钮) 6.CheckBox(复选框) 7.RadioGroup(单选按钮组) 8.Spinner(下拉列表组件) 9.ProgressBar(进度条) 10.SeekBar(拖动条) 11.RatingBar(评分组件) 12.ListView(列表) 13.Dialog(对话框) 14.Toast(信息提示组件)

1.1.2 TextView控件 1.2 TextView控件常用属性
1.android:layout_width(设置控件的宽度) 2.android:layout_height(设置控件的高度) 3.android:id(设置组件的ID) 4.android:text(设置文本的内容) 5.android:textColor(设置文本的颜色) 6.android:textSize(设置文本大小) 7.android:background(设置控件的背景颜色) 8.android:gravity(设置文本相对控件的位置) 9.android:layout_gravity(设置控件相对于其所在容器的位置)

TextView控件的使用首先要增加到布局文件中,即/res/layout/main.xml文件中.初始添加的TextView控件默认形式,如需要修改TextView的显示内容,字体大小等,有一下两种方式: (1)可以在XMl中修改某个属性的值来控制控件的表现形式 android:id属性声明了TextView的ID,这个ID主要用于在代码中引用这个TextView对象."@+id/tv1" 表示所设置的ID的值,@表示后面的字符串是ID资源,加好(+)便是需要建立新资源的名称,并添加到R.java文件中,斜杠(/)后面的字符串(TV1)表示新资源的名称. (2)可以通过代码获取这个空间的对象来修改其属性. 1.View在XML中必须已经配置id. 2.通过View的fndViewByid(int id)修改属性. import android.widget.TextView; public class MainActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savadInstanceState); setContenView(R.layout.activity_main); TextView tv = (TextView) findViewById(R.id.tv1); tv.setText("hello world"); tv.setTextSize(20); tv.setTextColor(0xFFFFFF); tv.setBackgroundColor(0xFF00FF); } }

创建一个APP的基本步骤: 步骤1.创建布局文件 "res/layout/activity_main.xml"布局文件位于layout文件夹下面,是界面显示的具体内容.创建方式有以下两种. (1)直接写布局代码:可以直接修改布局文件 (2)图形化界面布局:通过Design进行设置,拖放布局 步骤2.新建"MainActivity"类,创建Activity. Activity直观的理解就是手机屏幕上的一个界面,Activity主要作用是将界.面呈现出来Activity是Android系统中的四大组件之一,可以用于显示View可是控件.Activity是一个与用户交互的系统模块,几乎所有的Activity都是和用户进行交互的.交互的具体作用:一是显示;二是人机互动. 在MainActivity中重写Activity父类的onCreate()方法.onCreate方法为必须重写的方法,主要工作有一下两项: (1)完成布局界面的显示 protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } (2)建立相关的事件响应: //确认按钮 Button button = (Button)findViewById(R.id.btn_login); button.setOnClickListener(new OnClickListener(){ }) 步骤3.添加"登录"的按钮事件:当用户单击"登录"按钮时,弹出提示框并显示用户输入的用户名于密码,其具体事件逻辑如下: button.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0){ String userName = ev_userName.getText().toString(); String password = ev_password.getText().toString(); Toast.makeText(MainActivity.this,"用户名:"+ userName + "密码:" + password, Toast.LENGTH_LONG).show(); } });

附个人信息维护界面,步骤如下: 步骤1.创建布局文件,并选择黑的整体布局方式.根据目标界面,可以选用垂直方向的LinearLayout布局控件进行布局,代码如下: <LinearLayout xmlns:android="schemas.android.com/apk/res/and…" xmlns:tools="schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" 步骤2.添加用户的头像,在上述垂直方向的LinearLayout布局中嵌套一个垂直方向的LinearLayout布局,用来添加头像的文字说明及头像的图片,代码如下: <LinearLayout xmlns:android="schemas.android.com/apk/res/and…" xmlns:tools="schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="头像"
        android:textColor="@android:color/black"
        android:textSize="20sp"/>
    
    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp" 
        android:src="@mipmap/ic_launcher"/>
</LinearLayout>
   </LinearLayout>
复制代码

步骤3.添加用户姓名,在第一步的LinearLayout布局中在嵌套一个横向排列的LinearLayout布局,添加姓名的文字说明及姓名输入框,代码如下:

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:gravity="center"
        android:text="姓名"
        android:textColor="@android:color/black"
        android:textSize="20sp"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/et_name"/>
</LinearLayout>
复制代码

步骤4.添加用户性别,在第一步的LinearLayout布局中在继续嵌套一个横向排列的LinearLayout布局,添加性别的文字说明及性别的单选按钮,代码如下:

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:gravity="center"
        android:text="我的性别是"
        android:textColor="@android:color/black"
        android:textSize="20sp"/>

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        android:id="@+id/rg">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_teenager"
            android:layout_marginRight="@dimen/activity_vertical_margin"
            android:checked="true"
            android:text="男"
            android:textSize="20sp"/>

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_lolita"
            android:layout_marginLeft="@dimen/activity_vertical_margin"
            android:text="女"
            android:textSize="20sp"/>
    </RadioGroup>
</LinearLayout>
复制代码

步骤5.添加用户喜欢的专业,在第一步LinearLayout布局中在嵌套一个纵向排列的LinearLayout布局,添加专业的文字说明及专业的多选按钮,代码如下:

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我喜欢的专业:"
        android:textColor="@android:color/black"
        android:textSize="20sp"/>
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/chb_java"
        android:text="Java"
        android:textSize="20sp"/>
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/chb_android"
        android:text="Android"
        android:checked="true"
        android:textSize="20sp"/>
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/chb_math"
        android:text="高数"
        android:textSize="20sp"/>
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/chb_english"
        android:text="英语"
        android:textSize="20sp"/>
    <Button
        android:id="@+id/btn_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="确定"
        android:textSize="22sp" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        android:layout_marginTop="20sp"
        android:orientation="horizontal" >
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Ip:"
            android:textSize="20sp"/>
        <EditText
            android:id="@+id/et_ip"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="9"
            android:inputType="number"/>
    </LinearLayout>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tv_showIp"
        android:hint="192.168.1.1"
        android:paddingLeft="10dp"
        android:textSize="20sp" />
</LinearLayout>
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值