我使用过的 控件的一些特性(layout_weight,paddingleft)

来源:互联网 发布:钢结构节点计算软件 编辑:程序博客网 时间:2024/04/29 20:09

以Button为例,但不限于Button,其他的控件都可以使用

代码中常用属性:

Button bt=new Buttion(Context context);

bt.setText();---为控件设置文本内容


xml中常用属性:

android:layout_width=""---控件宽

android:layout_height=""---控件高

android:layout_weight=""---控件权重

表示一个区域,几个控件根据权重来进行相应的大小分配(感觉优先级高于 lauout_width 和 layout_height)

android:paddingLeft = "75dp"   距离左边控件距离

android:text=""---控件上的文本内容

android:onClick="doClick"---点击此控件时调用的方法---方法名称为:doClick

android:drawableTop=""---在Button组件上放置图片


补充:

1,控件样式常用属性 

android:id —— 为控件指定相应的ID
android:text —— 指定控件当中显示的文字,需要注意的是,这里尽量使用strings.xml文件当中的字符串
android:grivity —— 指定控件的基本位置,比如说居中,居右等位置
android:textSize —— 指定控件当中字体的大小
android:background —— 指定该控件所使用的背景色,RGB命名法 
android:width —— 指定控件的宽度
android:height —— 指定控件的高度
android:padding* —— 指定控件的内边距,也就是说控件当中的内容
android:sigleLine —— 如果设置为真的话,则将控件的内容在同一行当中进行显示
-->


2.控件相对布局常用属性 

android:layout_above 将该控件的底部至于给定ID的控件之上
android:layout_below 将该控件的顶部至于给定ID的控件之下
android:layout_toLeftOf 将该控件的右边缘和给定ID的控件的左边缘对齐
android:layout_toRightOf 将该控件的左边缘和给定ID的控件的右边缘对齐

android:layout_alignBaseline 该控件的baseline和给定ID的控件的baseline对齐
android:layout_alignBottom 将该控件的底部边缘与给定ID控件的底部边缘
android:layout_alignLeft 将该控件的左边缘与给定ID控件的左边缘对齐
android:layout_alignRight 将该控件的右边缘与给定ID控件的右边缘对齐
android:layout_alignTop 将给定控件的顶部边缘与给定ID控件的顶部对齐
android:alignParentBottom 如果该值为true,则将该控件的底部和父控件的底部对齐
android:layout_alignParentLeft 如果该值为true,则将该控件的左边与父控件的左边对齐
android:layout_alignParentRight 如果该值为true,则将该控件的右边与父控件的右边对齐
android:layout_alignParentTop 如果该值为true,则将空间的顶部与父控件的顶部对齐

android:layout_centerHorizontal 如果值为真,该控件将被至于水平方向的中央
android:layout_centerInParent 如果值为真,该控件将被至于父控件水平方向和垂直方向的中央
android:layout_centerVertical 如果值为真,该控件将被至于垂直方向的中央


原创粉丝点击