android最基本的控件使用

来源:互联网 发布:anaconda linux下安装 编辑:程序博客网 时间:2024/06/11 19:03

相信每个Android的软件都是要有人机交互界面的吧。所以说,控件的使用就像穿衣服,写好了就是美女,写不好就成了矮穷挫了。废话少多,进入正题。

1.<LinearLayout                                                   //线性布局

xmlns:android="http://schemas.android.com/apk/res/android"               //xml的命名空间

    android:orientation="vertical"                                //整个Activity是水平还是垂直布局
    android:layout_width="fill_parent"                       //该控件填满父控件
    android:layout_height="wrap_content"              //填满内容所占空间大小
    >

2.<TextView                                                                //手机屏幕上显示的字的方法
   android:id="@+id/firetText"                                   //设置ID,然后调用它的值
    android:text="ONE"                                                //显示字的名字
   android:textColor="#aa0000"                              //字体显色
   android:textSize="35pt"                                        //字体大小
   android:singleLine="true"                                    //是否在一行显示所有本控件的所有字(显示不下用“……”代替)
   android:background="#0000aa"                       //控件的背景颜色

 android:padding="11dip"                                     //控件与边框的距离

   android:gravity="center_vertical"                      //控件显示形式
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_weight="1"       />     //该控件占据整个手机屏幕空间的比例大小

<EditText                      //可输入文本框
   android:text="faction"
   android:hint="faction01" //设置EditText为空时输入框内的提示信息。 
  />

3.<RelativeLayout                                //相对布局
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:padding="10pt">
    />

4.RelativeLayout中比较重要的布局

1) 属性值为真或者假

 android:layout_centerHrizontal  水平居中 
     android:layout_centerVertical   垂直居中 
    android:layout_centerInparent    相对于父元素完全居中 
    android:layout_alignParentBottom 贴紧父元素的下边缘 
    android:layout_alignParentLeft   贴紧父元素的左边缘 
    android:layout_alignParentRight  贴紧父元素的右边缘 
    android:layout_alignParentTop    贴紧父元素的上边缘 
    android:layout_alignWithParentIfMissing  如果对应的兄弟元素找不到的话就以父元素做参照物 

2).属性值用ID来引用

    android:layout_below      在某元素的下方 
    android:layout_above      在某元素的的上方 
    android:layout_toLeftOf   在某元素的左边 
    android:layout_toRightOf  在某元素的右边 

    android:layout_alignTop   本元素的上边缘和某元素的的上边缘对齐 
    android:layout_alignLeft  本元素的左边缘和某元素的的左边缘对齐 
    android:layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐 
    android:layout_alignRight  本元素的右边缘和某元素的的右边缘对齐 

 

    3).属性值为特定的像素值。例如10px。。。
    android:layout_marginBottom              离某元素底边缘的距离 
    android:layout_marginLeft                   离某元素左边缘的距离 
    android:layout_marginRight                 离某元素右边缘的距离 
    android:layout_marginTop                   离某元素上边缘的距离 

 


原创粉丝点击