Android布局常用属性

布局
1.布局分为线性布局(linearlayout),
	  表格布局(tablelayout),
	  网格布局(gridlayout),
	  帧布局(framelayout),
	  绝对布局(absolutelayout),
	  相对布局(relativelayout),
	  rtl布局(right to left),
	  其中,绝对布局不常用,网格布局与rtl布局是在Android 4.0后出现的。




2.共有的属性
	
	layout_height : 控制当前控件在容器中所占高度;


	layout_width : 控制当前控件在容器中所占宽度;


	二者的取值范围:分为wrap_content , fill_parent ,match_parent ,


	其中,它们三者的含义与区别:
		wrap_content:强制将控件的大小扩展以显示控件的全部内容;


		fill_parent:强制将控件的大小扩展到容器的最大大小;


		match_parent:同fill_parent一样,区别在于后者在Android 2.2版本以下都可用,而前者不行;
	
	
		一些固定值:dp ,sp ,mm ,px




	android:layout_grivity:针对控件本身而言,设置当前控件在父容器中的位置,
		可取值:top ,bottom ,left ,right ,center_vertical(垂直居中) ,center_horizontal (水平居中),center(居中),fill_vertical(垂直填充),fill_horizontal(水平填充)


		特殊情况:当父容器的orientation被设置为vertical时,所有垂直方向的设置都将不起作用;而被设置为horizontal时,所有水平方向的设置也将不起作用	android:layout_margin:控件的外边框
	android:layout_marginTop:控件的上外边框
	android:layout_marginButtom:控件的下外边框


	orientation:容器中控件排列的方向,取值为horizontal ,vertical


	android:gravity:针对此控件中的元素而言,控制控件在容器中的显示位置


	android:id:有两种:@id/name 和 @+id/name ,区别在于前者作用用于引用,后者表示如果没有此属性,则会进行添加;




表格布局
	
	android:shrinkColumns:某些列被收缩
	android:stretchColumns:某些列被拉伸
	android:collapseColumns:某些列被隐藏
	android:layout_span:让某列跨列
	


网格布局


	rowCount:指定布局中有多少行
	columnCount:指定布局中有多少列
	layout_rowSpan:设置此控件跨行
	layout_columnSpan:设置控件跨列
	


绝对布局


	layout_x 与 layout_y :控制控件的坐标
	但由于屏幕大小和分辨率的变化,位置也会变化,所以不推荐使用




相对布局


	android:layout_alignParentBottm:设置为true,则将该控件与父控件进行底部对齐 
	android:layout_alignParentLeft:设置为true,将该控件与父控件进行左对齐
	android:layout_alignParentRight:设置为true,将该控件与父控件进行右对齐
	android:layout_alignParentTop:设置为true,将改控件与父控件进行顶部对齐
	android:layout_centerHorizontal:设置为true,将该控件水平居中
	android:layout_centerVertical:设置为true,将该控件垂直居中
	android:layout_centerInParent:设置为true,将该控件水平垂直居中


	
	android:layout_above:将该控件设置为给定控件之上
	android:layout_below:将该控件设置为给定控件之下 
	android:layout_toLeftOf:将该控件设置为给定控件的左边
	android:layout_toRightOf:将该控件设置为给定控件的右边
	android:layout_alignBaseline:将该控件的baseline与给定控件的baseline对齐
	android:layout_alignBottom:将该控件跟给定控件底部对齐
	android:layout_alignLeft:将该控件跟给定控件左对齐
	android:layout_alignRight:将该控件跟给定控件右对齐
	android:layout_alignTop:顶部对齐
 
 
 
 
	分享使人进步!
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值