Android 基础(三)、User Interface

来源:互联网 发布:手机知乎提问没人回答 编辑:程序博客网 时间:2024/05/16 01:59

Activitys shemselves are made up of sub-components called views

1、View是什么?

Views是用户能看见并且交互的部分。
Views处理layout(布局),提供按钮,允许在屏幕上绘图等等

Activity是symphony(交响乐),View就是音乐家

View需要乐器(instruments),Views和其他components充分利用colors,strings,styles,graphics,and the like(这些数据都会被complie成binary form)

2、R.java的作用是在Android binary references和source resources之间搭建桥梁

3、activitys,views,resources之间关系如下

activity

4、自己的activity所做的重要事情

  1. it gives our application a “context,” because Activity itself extends android.app.ApplicationContext ;
  2. it brings the Android life-cycle methods into play;
  3. it gives the framework a hook to start and run your application;
  4. it provides a container into which View elements can be placed.

5、onCreate中setContentView方法的作用

将XML布局view文件联系起来。此外可以使用代码配置View

XML是静态的,作为View tree的一部分

6、adapter(适配器)是做什么的?

adapter来链接(Link)包含数据的Views。
adapter返回collections中的每个item(以View的形式)

ArrayAdapter

在Context(this)上非常流行,View的element定义在XML resource file上,使用array数组来表示数据(也define在XML中)

Spinner的使用

ArrayAdapter<String> cuisines = new ArrayAdapter<String>(this, R.layout.spinner_view, this.getResources().getStringArray(R.array.cuisines));//适配器对象初始化cuisines.setDropDownViewResource(R.layout.spinner_view_dropdown);//设置下拉的View样式this.cuisine.setAdapter(cuisines); //设置适配器

7、onCreateOptionsMenu创建menu items的样式

menu.add能增加一个item
setIcon设置item的样子

onMenuItemSelected设置menu item的监听器

0 0