1 如何开发一个UI
a) 拖拽
b) 编码
c) xml 书写
dip = dp
2 <TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="suns"
android:textColor="#"
android:textSize=" sp"
android:background="#"
android:id="@+id/xxxx"
android:gravity="对其方式"
android:autoLink="web|phone"
> ---> R.id.xxx
</TextView> @drawable/xxxx
<Button>
</Button>
<EidtText android:text />
3 ui组件加入监听
1 程序获得UI组件对象
TextView tv = (TextView)findViewById(R.id.xx);
Button btn = (Button)findViewById(R.id.xxx);
2 设置监听程序
btn.setOnClickListener(new OnClickListener(){
public void onClick(View v){
xxxxx
}
});
问题
1 findViewById() ---- 放置 setContentView()后面
ViewButton 图形按钮
<ImageButton
android:src="@drawable/xxx"/>
指定按钮中显示的图片
android:background=""
ImageView 显示 图片
---------------------------------------------------
ToggleButton 切换按钮
1 ToggleButton.setOnCheckedChanageListener();
2 onCheckedChange --- > isCheched 确定按钮的开关
RadioButton 单选按钮
1 页面
2 编码设置监听
CheckBox 复选框
1 页面
2 编码设置监听
------------------------------------------
布局
UI控件在Activity页面中显示的结构
注意:1 任何android页面 都要由布局
2 所有的ui标签必须作为布局标签的子标签
1 线性布局
1 xml 拖拽式
2 编码在布局中设置元素
2 绝对布局 (很少)
绝对布局中 是通过控件坐标的方式定义控件的显示位置
页面左上角
android:layout_x dip
android:layout_y dip
3 表格布局
注意: <TableRow>
</TableRow>
4 相对布局
UI元素对其父标签的位置
android:layout_alginParentTop=true
layout_alginParentBottom=true
layout_alginParentLeft=true
layout_alginParentRight=true
centerInParent=true 正中间
centerVertical="true" 纵向中间
centerHorizontal="true" 横向中间
相对布局的基准点
相对点的定义
layout_below="@+id/xxx"
layout_above="@+id/xxx"
layout_toLeftOf="放置基准点的左边"
toRightOf="放置基准点的右边"
layout_alignLeft="和基准点左对其"
alignTop=""
alignRight=""
alignBottom=""
设置边距
layout_marginLeft=
Right=
Top=
Bottom=
5 帧布局 Frame
帧布局 父元素的左上角为基准点
1 如果后续元素 大小大于 前面的元素 覆盖前面的元素
2 如果后续元素 大小小于 前面的元素 则填充到前面的元素中
6 布局可以嵌套
---------------------------------------------------------
android 使用多个页面的方式
0) 如何开发一个Activity
1 写类
extends Activity{
public void onCreate(){
super.oncCreate();
xxxx
}
}
2 AndroidMenifest.xml 配置
1) 一个Activity 显示多个页面
setContentView(R.layout.xxx);
2) 不同的Activity中显示多个页面
//1 创建意图
Intent i = new Intent();
//2
i.setClass(MyActivity,ToActivity.class);
//3
startActivity(i);
----------------------------------------
1 布局
注册页面
2 练习 如何在一个应用中显示多个页面