zoukankan      html  css  js  c++  java
  • Android的方法和属性(2)

    1.RadioButton(单选按钮)
      嵌入到RsdioGroup中实现单选效果
      android:checkedButton="radio的id值"

      int getCheckedRadioButtonId(); //获得被选中的radionutton的id

     1  <RadioGroup
     2          android:layout_width="fill_parent"
     3         android:layout_height="wrap_content"
     4         android:checkedButton="@+id/rb2"
     5         >
     6      <RadioButton
     7          android:id="@+id/rb1"
     8          android:layout_width="fill_parent"
     9         android:layout_height="wrap_content"
    10         android:text="西瓜"
    11     />
    12     <RadioButton
    13         android:id="@+id/rb2"
    14          android:layout_width="fill_parent"
    15         android:layout_height="wrap_content"
    16         android:text="苹果"
    17     />
    18 </RadioGroup>
    代码示例

    2.ImageView(图片控件)
      android:src //图片的资源id
      android:maxWidth //最大宽度
      android:maxHeight //最大高度
      android:adjustViewBounds //设置为true,则maxWidth和maxHeigth生效

    3.ImageButton(图片按钮)

     1     <ImageView
     2         android:layout_width="fill_parent"
     3         android:layout_height="wrap_content"
     4         android:maxWidth="50px"
     5         android:maxHeight="50px"
     6         android:adjustViewBounds="true"
     7         android:src="@drawable/a"
     8     />
     9     <ImageButton
    10         android:layout_width="fill_parent"
    11         android:layout_height="wrap_content"
    12         android:src="@drawable/p"
    13     />
    代码示例


    4.TimePicker(时间控件)
    5.DatePicker(日期控件)
      //修改日期
      void updateDate(int year,int monthOfYear,int dayOfMonth)
      注意:monthOfYear是从0~11表示1-12月

     1 <TimePicker
     2          android:id="@+id/tp"
     3          android:layout_width="fill_parent"
     4         android:layout_height="wrap_content"
     5      />
     6      <DatePicker
     7          android:id="@+id/dp"
     8          android:layout_width="fill_parent"
     9         android:layout_height="wrap_content"
    10      />
    代码示例


    6.Spinner
      6.1下拉列表项的配置方式
        a.资源文件配置
          第一步:在string.xml配置
            <string-array name="citys">
              <item>上海</item>
              <item>长沙</item>
              <item>益阳</item>
            </string-array>
          第二步:指定资源
          android:entries="@array/citys"
        b.适配器配置
          第一种:资源配置
            ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(this, 资源id, 列表显示的样式);
          第二种:列表配置
            ArrayAdapter<CharSequence> adapte=new ArrayAdapter<CharSequence>(this,列表显示的样式,集合数据);

     1 <Spinner
     2          android:id="@+id/sp1"
     3          android:layout_width="fill_parent"
     4         android:layout_height="wrap_content"
     5         android:prompt="@string/city"
     6         android:entries="@array/citys"
     7      />
     8      <Spinner
     9          android:id="@+id/sp"
    10          android:layout_width="fill_parent"
    11         android:layout_height="wrap_content"
    12         android:prompt="@string/city"
    13         android:entries="@array/citys"
    14      />
    15 
    16 
    17 <string name="city">城市</string>
    18     <string-array name="citys">
    19         <item>上海</item>
    20         <item>长沙</item>
    21         <item>益阳</item>
    22     </string-array>
    代码示例
  • 相关阅读:
    flash背景透明、置底、禁止放大 右键菜单
    SQL 命令
    php无刷新翻页,单独的一个文件加上一个JS即可搞定
    php jquery ajax无刷新评论 无刷新翻页,字数统计 绝对可以用
    input点击隐藏显示层
    jquery延迟加载图片
    用Javascript读取CheckBox数组的值
    链表结构_C语言实现
    struts2_自定义错误提示
    struts2_自定义对象设置
  • 原文地址:https://www.cnblogs.com/yang82/p/6875774.html
Copyright © 2011-2022 走看看