探究android控件及布局
控件(widget)
1. TextView(该控件的一些需要注意的属性,下同)
gravity="center"textSize="24sp"textColor="#00ff00"
(完整的前面应该加android:,为了方便均忽略)
2. EditText
hint="Type something here"maxLines="2"
3. ImageView
src="@drawable/ic_launcher"imageView.setImageResoure(R.drawable.jetlly)
4. ProgressBar
1 |
progressBar.setVisibility(View.GONE)//设置不可见,且不占用任何空间 |
实际上需要去添加逻辑(比如当数据加载完成时执行:
1 |
progressBar.setVisibility(View.GONE)//设置不可见,且不占用任何空间 |
不然,ProgressBar会一直转
还有功能:
1 |
progressbar.getVisibility() |
在ProgressBar参数中style="?android:attr/progressBarStyleHorizontal"
可将进度条变成水平,参数max="100"设置水平进度条的最大值
5. AlertDialog
1 |
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);//可以理解为对话框建立在这个活动之上 |
注意:AlertDialog在程序里面写,不再布局里写
6. ProgressDialog
1 |
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this); |
与AlertDialog类似
四大布局(Layout)
1. LinearLayout
layout_gravity属性
orientation的方向一定是与layout_gravity方向正交,解释如下:
如果orientation="vertical",那么就只有水平方向的对齐有效
此时控件的layout_gravity"就有三种值:
- left
- center_horizontal
- right
同理,如果orientation="horizontal"
此时控件的layout_gravity有三种值:
- top
- center_vertical
- bottom
####### layout_weight(权重)
若orientation="horizontal",此时xml中有EditText和Button,设置他们的layout_width="0dp",若设置EditText的layout_weight="3",设置Button的layout_weight="2",前者占屏幕的3/5,后者占2/5
2. RelativeLayout
控件相对父布局定位
- layout_alignParentTop
- layout_alignparentBottom
- layout_alignParentRight
- layout_alignParentLeft
- laout_centerInParent
控件相对控件定位
- layout_below
- layout_toRightOf
- layout_toLeftOf
- layout_above
边缘对齐(就试验的情况下,貌似此处orientation不顶用)
- layout_alignLeft
- layout_alignRight
- layout_alignTop
- layout_alignBottom
3. FrameLayout
所有控件都摆放在左上角
4.TableLayout
1 |
//一对这样的标签就表示一行 |
- 需要注意的是,《第一行代码》中当一行有
TextView和EditText时,TextView只有layout_height属性,这可能是由于TableLayout有自己的关于每行中列宽度的规定,以后遇到这种情况再做更正 - 合并单元格:
layout_span="2"表示横跨两列 - TableLayout头部添加
android:stretchColumns="1",即将第二列拉伸,0则拉伸第一列
探究android控件及布局的更多相关文章
- Android 控件在布局中按比例放置[转]
转自:http://netsky1990.blog.51cto.com/2220666/997452 在Android开发中常用到线性布局LinearLayout对界面进行具体的创建,其中 ...
- android控件基本布局
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=&qu ...
- Android 手机卫士--自定义组合控件构件布局结构
由于设置中心条目中的布局都很类似,所以可以考虑使用自定义组合控件来简化实现 本文地址:http://www.cnblogs.com/wuyudong/p/5909043.html,转载请注明源地址. ...
- Android编程 控件与布局
控件和布局的继承结构 常用控件 1.TextView <?xml version="1.0" encoding="utf-8"?> <Line ...
- Android 控件属性介绍
1.LinearLayout(线性布局): 可以分为水平线性:android:orientation= " horizontal " 和垂直线性:android:orientati ...
- Android控件Gridview实现仿支付宝首页,Fragment底部按钮切换和登录圆形头像
此案例主要讲的是Android控件Gridview(九宫格)完美实现仿支付宝首页,包含添加和删除功能:Fragment底部按钮切换的效果,包含四个模块,登录页面圆形头像等,一个小项目的初始布局. 效果 ...
- Android 控件架构及View、ViewGroup的测量
附录:示例代码地址 控件在Android开发的过程中是必不可少的,无论是我们在使用系统控件还是自定义的控件.下面我们将讲解一下Android的控件架构,以及如何实现自定义控件. 1.Android控件 ...
- Android控件属性大全(转)
http://blog.csdn.net/pku_android/article/details/7365685 LinearLayout 线性布局 子元素任意: Tab ...
- UIAutomator定位Android控件的方法
UIAutomator各种控件定位的方法. 1. 背景 使用SDK自带的NotePad应用,尝试去获得在NotesList那个Activity里的Menu Options上面的那个Add note菜单 ...
随机推荐
- Python Challenge 过关心得(0)
最近开始用Openerp进行开发,在python语言本身上并没有什么太大的进展,于是决定利用空闲时间做一点python练习. 最终找到了这款叫做Python Challenge(http://www. ...
- CSS 总结
CSS 积累总结 1. ::Selection 选择器 使被选中的文本成为灰色: ::selection { color:#CCC; background:red; --- 选中背景颜色变成红色 } ...
- jsp 2种include标签的区别
众所周知,jsp中有2种标签用于包含其他jsp或者文件 1.include指令,其实是java代码 <%@ include file="xxx.jsp"%> 2.jsp ...
- 必学100个常用linux命令大全
1,echo “aa” > test.txt 和 echo “bb” >> test.txt //>将原文件清空,并且内容写入到文件中,>>将内容放到文件的尾部 2 ...
- [转]Geoserver实现WFS操作
From:http://liushaobo2005.blog.163.com/blog/static/253056702011541462372/ wfs是OGC的标准规范,主要用于提供对矢量地理数据 ...
- Another attempt about LSI
Last week I was here Natural Language Processing in NZ. Someone asked a question, is there any exist ...
- linux动态库加载时搜索路径
摘自http://gotowqj.iteye.com/blog/1926613 对动态库的实际应用还不太熟悉的读者可能曾经遇到过类似“error while loading shared librar ...
- hdu 5506 GT and set(dfs爆搜)
Problem Description You are given N sets.The i−th set has Ai numbers.You should divide the sets into ...
- Sereja and Suffixes(思维)
Sereja and Suffixes Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- asp.net 跨页面传值常用方法
常用方法有以下: 1.queryString 2.form-post控件传递 3.cookie 4.application 5.session querystring: http://website. ...