Android的方法和属性

千磨万击还坚劲,任尔东西南北风。这篇文章主要讲述Android的方法和属性相关的知识,希望能为你提供帮助。
1.RadioButton(单选按钮)
嵌入到RsdioGroup中实现单选效果
android:checkedButton="radio的id值"

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

Android的方法和属性

文章图片
Android的方法和属性

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

代码示例【Android的方法和属性】 
2.ImageView(图片控件)
android:src//图片的资源id
android:maxWidth//最大宽度
android:maxHeight//最大高度
android:adjustViewBounds//设置为true,则maxWidth和maxHeigth生效
3.ImageButton(图片按钮)
Android的方法和属性

文章图片
Android的方法和属性

文章图片
1< ImageView 2android:layout_width="fill_parent" 3android:layout_height="wrap_content" 4android:maxWidth="50px" 5android:maxHeight="50px" 6android:adjustViewBounds="true" 7android:src="https://www.songbingjia.com/android/@drawable/a" 8/> 9< ImageButton 10android:layout_width="fill_parent" 11android:layout_height="wrap_content" 12android:src="https://www.songbingjia.com/android/@drawable/p" 13/>

代码示例
4.TimePicker(时间控件)
5.DatePicker(日期控件)
//修改日期
void updateDate(int year,int monthOfYear,int dayOfMonth)
注意:monthOfYear是从0~11表示1-12月
Android的方法和属性

文章图片
Android的方法和属性

文章图片
1 < TimePicker 2android:id="@+id/tp" 3android:layout_width="fill_parent" 4android:layout_height="wrap_content" 5/> 6< DatePicker 7android:id="@+id/dp" 8android:layout_width="fill_parent" 9android: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,列表显示的样式,集合数据);


Android的方法和属性

文章图片
Android的方法和属性

文章图片
1 < Spinner 2android:id="@+id/sp1" 3android:layout_width="fill_parent" 4android:layout_height="wrap_content" 5android:prompt="@string/city" 6android:entries="@array/citys" 7/> 8< Spinner 9android:id="@+id/sp" 10android:layout_width="fill_parent" 11android:layout_height="wrap_content" 12android:prompt="@string/city" 13android: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>

代码示例 
































    推荐阅读