zoukankan      html  css  js  c++  java
  • android基础

    今天学习了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

      使窗体内容可以滚动

  • 相关阅读:
    已解决[Authentication failed for token submission,Illegal hexadecimal charcter s at index 1]
    远程快速安装redis和远程连接
    远程快速安装mysql
    Swiper的jquery动态渲染不能滑动
    微服务架构攀登之路(三)之gRPC入门
    微服务架构攀登之路(二)之RPC
    微服务架构攀登之路(一)之微服务初识
    Go语言中new和make的区别
    Go语言实战爬虫项目
    Go语言系列(十一)- 日志收集系统架构
  • 原文地址:https://www.cnblogs.com/RobotWorlds-li/p/4694831.html
Copyright © 2011-2022 走看看