码迷,mamicode.com
首页 > 移动开发 > 详细

android基础

时间:2015-08-01 23:21:22      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

今天学习了android 的布局部件和一些简单的控件的使用,特此总结一下。希望每天都有收获。

1.RadioButton  CheckBox都继承自CompoundButton (继承自TextView)

  公有的方法是:isChecked()判断是否选中了按钮,toggle()切换选中的状态

  共有的事件是:SetOnCheckedChangeListener监听

2.RadioGroup:单选按钮组

  方法:check() 用法是group.check(R.id.radio1),clearCheck()清除选中的按钮,getCheckedRadioButtonId(); 取得当前被选中的按钮的ID

3.部件方法

  setEnabled()可以启用或停用部件
  isEnabled()可以检测部件是否启用
  requestFocus()可以使某个部件获得焦点,isFocused()可以检测部件是否拥有焦点
  getParent()查找父部件或容器
  getRootView() 取得视图树的根部件(通过setContentView()提供的Activity的部件)
  getDecorView()取得UI的顶层View 用法getWindow().getDecorView()

4.TestView 设置文本的颜色SetTextColor()

5.布局的几种方式

  5.1.LinearLayout遵循盒模型,线性布局。

    方向(horizontal水平和ertical垂直的)

    方法setOrientation()动态改变方向参数是HORIZONTAL或VERTICAL

  关于fill_parent和wrap_content(wrap_content表示部件应该保持其本来的大小,fill_parent表示部件应该填满包含他的容器)

  重力andriod:layout_gravity特性,其值left,center_horizontal,right 分别表示左对齐,水平居中对齐和
  右对齐
  方法setGravity()

  内边距
  andriod:padding指部件边界与内容之间应该留出多大的距离

  5.2.RelativeLayout相对布局

  android:layout_alignParentTop:与容器的顶部对齐
  android:layout_alignParentBottom:与容器的底部对齐
  android:layout_alignParentLeft与容器的左侧对齐
  android:layout_alignParentRight与容器的右侧对齐
  android:layout_centerHorizontal水平居中
  android:layout_centerVertical垂直居中
  android:layout_centerInParent水平和垂直居中
  这些属性取值true or false

  @+id/.. android部件的id值
  @id/ 引用其他的部件

  android:layout_above 表示当前部件位于相对部件的上方
  android:layout_below 下方
  android:layout_toLeftOf 左侧
  android:layout_toRightOf 右侧

  android:layout_alignTop 表示当前部件与相对部件的上边缘对齐
  android:layout_alignBottom 下边缘对齐
  android:layout_alignLeft 左边缘对齐
  android:layout_alignRight 右边缘对齐
  android:layout_alignBaseline 相对于基线对齐

  5.3.TableLayout表格布局

  layout_span 占据几行空间
  layout_column 索引从0开始,把当前部件放入哪一列中

  扩展 stretchColumns 索引从0开始
  收缩 shrinkColumns  索引从0开始
  折叠 collapseColumns 索引从0开始

  5.4.ScrollView

  使窗体内容可以滚动

android基础

标签:

原文地址:http://www.cnblogs.com/RobotWorlds-li/p/4694831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!