第9课 -------------------------------------------- Activiy的布局初步(一) 主要内容: LinearLayout的使用方法 TableLayout的使用方法 TextView中的android:gravity="top",指的是TextView中的text 位于TextView的top.而跟TextView在布局文件中的位置没有关系。 TextView如果设置属性android:singleline="true"的话,一行显示不完 的内容他会自动在行末尾加三个点。 android:panding指内边距 TableLayout是表格布局,通过使用 <TableRow> ...... </TableRow>这样的行标签,为表中的一行布局,把一行的内容都放在一个 行标签里面。每一项为一列,开始的列为第0列。 在TableLayout里面stretchColumns属性用来指定当所有的列不能填满父控件 的时候拉伸哪个列的空间。相反亦然。 第10课 -------------------------------------------- Activiy的布局初步(二) LinearLayout的嵌套使用。 第11课 -------------------------------------------- Activiy的布局初步(三) RelativeLayout相对布局 第12课 -------------------------------------------- 常用控件(二) 1.RadioGroup和RadoButton的使用方法 2.CheckBox的使用方法 3.Toast的基本用法 RadioButton叫做单选按钮,也就是同一时刻只能有一个按钮是选中状态, 也就是说,在一组单选按钮中同时有一个可以选中,当第二个被选中的时候, 第一个就变成不选中状态。RadioButton的text属性显示在按钮的后面。 每一个 <RadioButton> ... </RadioButton> 对象都要放置在 <RadioGrop> ...... </RadioGrop> 单选按钮组的对象里面。 设置监听器的时候,不是对单个的单选按钮设置,而是对单选按钮组进行 设置监听器。 setOnCheckedChangeLisener(); 在onCheckedChanged(RadioGroup group, int checkedID) 方法中,当我们点击RadioButton的时候,被点击的RadioButton的组和ID就 会被传进来,比如我们有一个对象命名为radioButton1的RadioButton。 那么当radioButton1被按下以后我们要执行的动作就设置在onCheckedChanged 里 if(radioButton1.getId() == checkedID){ ........ } CheckBox是多选按钮,没有组的概念 Toast用来显示一个提示信息,只需一行代码 第13课 -------------------------------------------- 常用控件(三) 1.ProgressBar的使用方法 2.ListView的使用 默认情况下,进度调是不可见的 android:visible=gone; 当在程序运行过程中需要使用进度条的时候,设置进度条可见: setVisibility(View.Visible); setProgrees(i);设置进度条的进度为i,默认的最大值为100. 但是可以通过android:max=20设置最大值。 setSecondProgrees(j);设置第二进度值。两个进度的的显示在颜色有区别。 ListView: 1.定义一个Activity A继承自ListActivity类而不再是继承Activity类 2.在main.xml中定义一个 <ListView android="@id/android:list"//使用android内置id android:scrollbars="vertical"//使用竖直滚动条 .......></ListView> 3.在A的onCreat方法中最后要执行 setListAdapter(listAdapter)方法//参数是一个适配器对象。 /***************** 主意的代码 ****************/ ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>(); HashMap<String,String> map1 = new HashMap<String,String>(); HashMap<String,String> map2 = new HashMap<String,String>(); HashMap<String,String> map3 = new HashMap<String,String>(); map1.put("user_name","zhang1"); map1.put("user_ip","192.168.0.1"); map2.put("user_name","zhang2"); map2.put("user_ip","192.168.0.2"); map3.put("user_name","zhang3"); map3.put("user_ip","192.168.0.3"); list.add(map1); list.add(map2); list.add(map3); SingleAdapter listAdapter = new SingleAdapte( this, list, R.layout.user, new String[]{"user_name","user_ip"}, new int[]{R.id.user_ip,R.id.user_name}); setListAdapter(listAdapter); /***********************************************************./ 其中R.layout.user是为ListView中每一行设置的布局。其中有两个 TextView,他们的id分别是user_name和user_ip.