Android学习笔记--控件&布局
2013-10-28 20:54
176 查看
原文地址:Android学习笔记--控件&布局作者:inonoclas1、启动发短信的代码
Uri uri = Uri.parse("smsto://13800000000");
Intent intent = new (Intent.ACTION_SENDTO,uri);
intent.putExtra("sms_body","The SMS text");
startActivity(intent);
二、常用控件:
Button TextView 分别为按钮和文本
1、EditTextView 文本编辑框:
得到控件的值
String value = editTextViewName.getText().toString();
2、菜单:
点击主菜单调用
onCreateOptionsMenu(Menu menu){
menu.add(0,1,1,R.String.about);
}
点击菜单中的选项调用
onOptionsItemselected(MenuItem item){
判断item.getItemId()
{
执行操作
}
}
P.S:动态布局时,程序当中也对控件进行布局,并非所有布局文件都放在xml中声明
3、RadioGroup、RadioButton 单选按钮:
RadioGroup中包含若干RadioButton,
设置监听器:
new RadioGroup.onCheckedChangeListener{
public void onCheckedChanged(RadioGroup group,int
checkedId){
checkedId判断{
执行操作
}
}
}
CheckBox 多选按钮:
设置监听器:
new CompoundButton.onCheckedChangeListener{
public void onCheckedChanged(CompoundButton
buttonView,boolean is Checked){
idChecked判断{
执行操作
}
}
}
注意CheckBox和RadioGroup的监听器有所不同
Toast 弹出提示框:
Toast.makeText(Context context,String Show_str,int
time).show();
4、ProgressBar 进度条
布局文件属性:
visibility、style、id、layout_width、layout_height、max
对象 progressBar
progressBar.setProgress(i)
progressBar.setMax(200)
progressBar.setSecondProgress(i+10)
默认的进度条无法显示进行的状态
ListView:
activity应继承ListActivity
SimpleAdapter类添加存储数据
SimpleAdapter simpleAdapter = new
SimpleAdapter(this,list,R.layouput.user,new
String[]{"属性名1","属性名2",...},new
int[]{R.id.user_ip,R.id.user_name,...})
其中list为存放map的列表,map中存放属性名和属性值的键值对,R.layouput.user为一个布局文件,R.id.user_ip为布局文件中对应属性名1的控件
setListAdapter(simpleAdapter)
点击ListView中的item调用的函数(非监听模式)
onListItemClick(ListView l,View v,int postion,long id){
// l 当前的Listview,v
当前点击的item,postion 当前item的位置,id
当前item的id 点击listView中的某一个item而执行的操作
}
三、布局初步
id、text、grivity(控件内容的布局)、textSize、backgroud、layout_width、layout_height、padding(left、right、top、buttom):内边距、margin(left、right、top、buttom):外边距、sigleLine(为true时,控件中的内容在同一行中显示)、layout_weight(在同一个标签级别下的控件相对大小)
线性布局
LinearLayout:
orientation:vertical、horizontal
表格布局
TableLayout:
stretchColumns指定拉伸列
TableRow(定义一行在其中按水平线性布局)
嵌套布局
<LinearLayout 线性纵向布局>
<LinearLayout 线性横向布局>
<TextView/>
<TextView/>
<TextView/>
</LinearLayout 线性横向布局>
<LinearLayout 线性纵向布局>
<TableLayout 表格布局>
<TableRow>
<TextView/>
<TextView/>
</TableRow>
<TableRow>
<TextView/>
<TextView/>
<TextView/>
</TableRow>
</TableLayout 表格布局>
</LinearLayout 线性纵向布局>
</LinearLayout 线性纵向布局>
相对布局
RelativeLayout
layout_above(放置在另一个控件的底部):@id/另一个控件的id、layout_below、layout_toleftof、layout_torightof;layout_alignBaseline(与另一个控件底部对齐)、layout_alignBottom、layout_alignLeft、layout_alignRight、layout_alignTop;layout_alignParentBottom(为真时控件底部与父控件的底部对齐)、layout_alignParentRight、layout_alignParentLeft、layout_alignParentTop;layout_centerHorrizental(为真时控件放置于水平方向的中央)、layout_centerItnParent(为真时控件放置于父控件水平和垂直方向的中央)、layout_centerVertical(为真时将控件放置在处置方向的中央)、
Uri uri = Uri.parse("smsto://13800000000");
Intent intent = new (Intent.ACTION_SENDTO,uri);
intent.putExtra("sms_body","The SMS text");
startActivity(intent);
二、常用控件:
Button TextView 分别为按钮和文本
1、EditTextView 文本编辑框:
得到控件的值
String value = editTextViewName.getText().toString();
2、菜单:
点击主菜单调用
onCreateOptionsMenu(Menu menu){
menu.add(0,1,1,R.String.about);
}
点击菜单中的选项调用
onOptionsItemselected(MenuItem item){
判断item.getItemId()
{
执行操作
}
}
P.S:动态布局时,程序当中也对控件进行布局,并非所有布局文件都放在xml中声明
3、RadioGroup、RadioButton 单选按钮:
RadioGroup中包含若干RadioButton,
设置监听器:
new RadioGroup.onCheckedChangeListener{
public void onCheckedChanged(RadioGroup group,int
checkedId){
checkedId判断{
执行操作
}
}
}
CheckBox 多选按钮:
设置监听器:
new CompoundButton.onCheckedChangeListener{
public void onCheckedChanged(CompoundButton
buttonView,boolean is Checked){
idChecked判断{
执行操作
}
}
}
注意CheckBox和RadioGroup的监听器有所不同
Toast 弹出提示框:
Toast.makeText(Context context,String Show_str,int
time).show();
4、ProgressBar 进度条
布局文件属性:
visibility、style、id、layout_width、layout_height、max
对象 progressBar
progressBar.setProgress(i)
progressBar.setMax(200)
progressBar.setSecondProgress(i+10)
默认的进度条无法显示进行的状态
ListView:
activity应继承ListActivity
SimpleAdapter类添加存储数据
SimpleAdapter simpleAdapter = new
SimpleAdapter(this,list,R.layouput.user,new
String[]{"属性名1","属性名2",...},new
int[]{R.id.user_ip,R.id.user_name,...})
其中list为存放map的列表,map中存放属性名和属性值的键值对,R.layouput.user为一个布局文件,R.id.user_ip为布局文件中对应属性名1的控件
setListAdapter(simpleAdapter)
点击ListView中的item调用的函数(非监听模式)
onListItemClick(ListView l,View v,int postion,long id){
// l 当前的Listview,v
当前点击的item,postion 当前item的位置,id
当前item的id 点击listView中的某一个item而执行的操作
}
三、布局初步
id、text、grivity(控件内容的布局)、textSize、backgroud、layout_width、layout_height、padding(left、right、top、buttom):内边距、margin(left、right、top、buttom):外边距、sigleLine(为true时,控件中的内容在同一行中显示)、layout_weight(在同一个标签级别下的控件相对大小)
线性布局
LinearLayout:
orientation:vertical、horizontal
表格布局
TableLayout:
stretchColumns指定拉伸列
TableRow(定义一行在其中按水平线性布局)
嵌套布局
<LinearLayout 线性纵向布局>
<LinearLayout 线性横向布局>
<TextView/>
<TextView/>
<TextView/>
</LinearLayout 线性横向布局>
<LinearLayout 线性纵向布局>
<TableLayout 表格布局>
<TableRow>
<TextView/>
<TextView/>
</TableRow>
<TableRow>
<TextView/>
<TextView/>
<TextView/>
</TableRow>
</TableLayout 表格布局>
</LinearLayout 线性纵向布局>
</LinearLayout 线性纵向布局>
相对布局
RelativeLayout
layout_above(放置在另一个控件的底部):@id/另一个控件的id、layout_below、layout_toleftof、layout_torightof;layout_alignBaseline(与另一个控件底部对齐)、layout_alignBottom、layout_alignLeft、layout_alignRight、layout_alignTop;layout_alignParentBottom(为真时控件底部与父控件的底部对齐)、layout_alignParentRight、layout_alignParentLeft、layout_alignParentTop;layout_centerHorrizental(为真时控件放置于水平方向的中央)、layout_centerItnParent(为真时控件放置于父控件水平和垂直方向的中央)、layout_centerVertical(为真时将控件放置在处置方向的中央)、
相关文章推荐
- 自己定义ViewGroup控件(二)----->流式布局进阶(二)
- android面试题目大全<第一部分>,android基本的UI控件和布局文件知识
- android学习笔记——GridView控件(九宫格布局)
- 、首先,我们添加一个主界面窗体,命名为MainForm,该窗体IsMdiContainer设置为True,也就是设置为多文档窗体格式。拖拉布局控件"WeifenLuo.WinFormsUI.Docking.DockPanel"到主窗体MainForm中,并
- WinForm界面开发之布局控件\"WeifenLuo.WinFormsUI.Docking\"的使用
- android编码规范 & 常用布局 & 常用控件
- 黑马66期android学习笔记14-电话拨号器定义布局&获取组件对象
- Android学习笔记(五):布局控件
- WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用
- WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用
- WPF小结(一&二) 布局和控件
- WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用
- WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用
- 布局控件"WeifenLuo.WinFormsUI.Docking"的使用--如何控制自动停靠窗口的大小
- 自己定义ViewGroup控件(一)----->流式布局进阶(一)
- 自定义ViewGroup控件(二)----->流式布局进阶(二)
- Android学习笔记:<二>03.Android当中的常用控件
- 三,android编码规范 & 常用布局 & 常用控件
- 布局&控件各种属性详解
- WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用