13年12月份

下面是部分基本组建的重点:

1)          TextView标签:主要代码

<TextView 

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="用户名:"

    android:textColor="#FF0000"

    //设置文本颜色

    android:typeface="monospace”

//设置标签字体,monospace等宽字体

    android:textStyle="bold"

    //标签的字体样式,粗体bold、斜体

/>

 

2)          Button按钮: Button是TextView的子类,所以TextView中的相关属性也是适合Button的, TextView只是负责显示,基本不会和用户进行交互。主要代码:

 <Button

    android:id="@+id/mybut"

//在布局文件里注册一个id

        android:text="按一下" //按钮框内显示的内容

    android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:textColor=”#FFFF00”

android:textSize=”12px”

/> 

 

3)          ImageView 图片视图

主要代码

< ImageView

android:id=”@+id/img”

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:src=”@drawable/logo”/>

 

4)          ImageButton图片按钮:用来显示图像功能的控件按钮。

主要代码

< ImageButton

android:id=”@+id/rig”

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:src=”@drawable/right”/>

 

5)          EditText编辑框,可以在文本编辑框内输入相关内容

主要代码

<EditText

android:id="@+id/myedt"

              android:text="www.baidu.cn"

//文本编辑框里面的内容

              android:layout_width="wrap_content"

              android:layout_height="wrap_content"

   />

 

6)          CheckBox复选框  复选框有两种状态:选中和未选中。当单击复选框可以在这两种状态中进行切换,以表示是选择还是不选。

主要代码

 

<CheckBox

android:id="@+id/cbcountry "

    android:text="美国"  //复选框内容

android:layout_width="wrap_content"

android:layout_height="wrap_content“

/>

7)          RadioButton单选钮: 单选按钮存在多个选中一个的问题,故必须将其放置在一个组中,即单选按钮必须结合RadioGroup进行使用。在RadioGroup不会在界面进行显示的,可以通过其android:id属性来区分不同的单选按钮组。

主要代码

<RadioGroup

android:id="@+id/RadioGroup1"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<RadioButton

android:text=”男”

      android:id="@+id/rbtnMan"

          android:layout_width="wrap_content" android:layout_height="wrap_content">

</RadioButton>

<RadioButton

android:text="女"

android:id="@+id/rbtnWoman"

android:layout_width="wrap_content" android:layout_height="wrap_content">

</RadioButton>

</RadioGroup>

8)          Spinner下拉列表:是一种能够从多个选项中选一个选项的控件。

主要代码

<Spinner  

    android:id="@+id/degree"  

    android:layout_width="fill_parent"  

android:layout_height="wrap_content" />

         xml

<string-array name="degrees">  

                   <item>初中及以下</item>  

                   <item>高中</item>  

                   <item>大学</item>  

                   <item>研究生及以上</item>  

</string-array>  

9)          TimePicker时间选择器,主要目的是可以进行时间的调整

主要代码

<TimePicker

android:id="@+id/tp1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

 

10)     DatePicker日期选择器,主要目的是可以进行日期的调整

主要代码

<DatePicker

android:id="@+id/dp1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

 

注:所有的组件需要设置android:layout_width ,android:layout_height属性,表示该组件与父容器的关系。

    所有的组建都需要按一定的方式显示在用户界面上,因此需要按一定的方式排列,下面罗列5种重要的布局:

1)          线性布局LinearLayout       又分为:                垂直布局vertical:每行只有一个元素,多个元素依次垂直向下                                             水平布局horizontal:只有一行,多个元素依次向右排列                                                               

2)          相对布局RelativeLayout:以某一个元素为参照物来确定其他元素的位置,如layout_below/toLeftOf/toRightOf

3)          框架布局FrameLayout:这个布局管理器可以理解成在一个墙角堆东西,已经放了一个东西在那里,如果要再放就只能放在原来放的上面,这样依次放会盖住原来的东西。

4)          表格布局TableLayout:每个表格管理器中有一个表格行TableRow, TableRow中可以具体定义每一个元素

5)          绝对布局AbsolutelyLayout:用X,Y坐标来指定元素的位置

以上5种布局,绝对布局已经逐渐被淘汰不再使用,线性布局是使用最多的一种布局管理器,这5个布局管理器可以嵌套应用,做出我们需要的效果。                                                                                                    当然在练习将所学习的的一些知识转换成代码运行时,不可避免的会经历各种语法错误,下面罗列一些:

1)          xml文件的一些标签错误,解决这类问题一般是采取将整个xml文件规范化,然后再观察(Ctrl A+ Ctrl I)

2)          内存不足,一般会显示memory或者storage。清理手机内存后再运行

3)          在程序中 R.xx.xxx 报错现象,

1. 对着工程点击鼠标右键 选择 Build Project,R.java 文件又回来。这样R.xx.xxx 就能 X 的出来了。

2. 选择eclipse/myeclipse 的 clean 这样R文件也会出现
经过上面两种方法都不行

3. 从别的工程中拷贝一份R文件过来然后string.xml里随便改动一下即可更新R文件
如果还不行,经过上面的3种方法都不行说明工程有问题 好好检查吧。
比如resoure资源中的文件 命名,例result_main.xml,如果写成Result_main.xml是错误的需要全部小写

posted @ 2014-02-19 14:16  几许清浅  阅读(142)  评论(0)    收藏  举报