一、View类的常用xml属性:(各种控件的共同属性)
  1. android:id
  2. android:background 设置背景图片
  3. android:layout_height 高度
  4. android:layout_width 宽度
  5. android:layout_gravity 设置该控件在起容器中的对齐方式
  6. android:layout_margin 设置外边距
  7. android:padding 设置控件四周的填充区域
  8. android:visibility 设置该控件是否可见

【备注:】sp、dp、dip、pt、px等单位的区别?
  1. dpi dpi指像素密度。dots per inch ,即每英寸内像素点的个数。它不是表示长度的单位。在android中认为:低(120dpi),中(160dpi),高(240dpi),超高(320dpi)。随着技术的增长,实际dpi已经超出这个定义范围。
  2. dip device independent pixels ,即与设备无关的像素。目前这个单位已经被dp所取代,而不建议使用dip。
  3. dp 与dip的概念一样。不过dp已经取代了dip。在Android中用来表示非文字大小的尺寸上。例如:外边距、内填充等。
  4. sp scale independent pixel ,即与缩放比例无关的像素。在android中常用来表示文字大小。
  5. px 表示像素。因为同样是200px,但是在不同手机下显示的大小是不同的。
  6. pt point磅。1磅=1/74英寸
  • 总之:dp是用来定义非文字的尺寸,sp用来定义文字大小。px只用于产生一条一像素的分割线时使用。


二、基本控件:【TextView 、EditText、Button、ImageView、ImageButton、RadioButton、Checkbox、Spinner】 (一)、TextView 、EditText 常用属性: 1、 andorid:text 设置文本的内容 2、 android:textColor 设置文本的颜色 3、 android:textSize 设置文本的字体大小 4、 andorid:height 设置文本的高度,以像素为单位 5、 android:width 设置文本的宽度,以像素为单位 6、 android:inputType 设置文本的类型。例如是普通文本,还是emial,passworid,数字等等。 7、 android:singleLine 设置文本是否是单行显示。 8、android:gravity 设置文本框内文本的对齐方式。可选项有:top、bottom、left、right、center、fill、center_vertical、center_horizontal、fill_horizontal等等。这些属性值也可以同时指定,各属性值之间用竖线隔开。 例如:right|bottom 9、 android:drawableLeft 用于在文本框左侧绘制图片。该属性值通过“@drawable/图片文件名”来设置。 10、android:drawableRight 用于在文本框左侧绘制图片。该属性值通过“@drawable/图片文件名”来设置。 11、android:drawableTop 用于在文本框左侧绘制图片。该属性值通过“@drawable/图片文件名”来设置。 12、android:drawableBottom 用于在文本框左侧绘制图片。该属性值通过“@drawable/图片文件名”来设置。 13、android:autoLink 给指定的文本增加可单击的超链接。可选项为:none、web、email、phone、map和all。 14、android:hint 设置当文本框内文本内容为空时,默认显示的提示性文字。
(二)、Button java.lang.Object ↳ android.view.View ↳ android.widget.TextView ↳ android.widget.Button
所以Button继承了TextView的所有属性。
(三)、ImageView 常用属性: 1、andorid:src 设置图片来源。属性值为android:src="@drawable/图片名称" 2、android:adjustViewBounds 用于设置 ImageView是否调整自己的边界,来保持所显示图片的长宽比例。属性值为true或false 3、android:maxHeight 设置 ImageView的最大高度。需要先设置android:adjustViewBounds为true,否则不起作用。 4、andorid:maxWidth 设置 ImageView的最大宽度。需要先设置android:adjustViewBounds为true,否则不起作用。 5、 android:scaleType 设置所显示的图片如何缩放或移动,以适应ImageView的大小。

(四)、ImageButton java.lang.Object ↳ android.view.View ↳ android.widget.ImageView ↳ android.widget.ImageButton
所以 ImageButton继承了 ImageView的所有属性。

(五)、RadioButton及RadioGroup 1.介绍: java.lang.Object ↳ android.view.View ↳ android.view.ViewGroup ↳ android.widget.LinearLayout ↳ android.widget.RadioGroup
java.lang.Object ↳ android.view.View ↳ android.widget.TextView ↳ android.widget.Button ↳ android.widget.CompoundButton ↳ android.widget.RadioButton
RadioButton继承于Button,所以具有普通按钮的各种属性,但是与普通按钮不同的是,RadioButton提供了可选中的功能。
2.核心代码:

<RadioGroup android:id="@+id/radioGroup1" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/radio_register_male" android:text="男" android:checked="true"/> <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/radio_register_female" android:text="女" />

</RadioGroup>

java代码:

radioGroup1.findViewById(R.id.radioGroup_main_show); radioGroup.OncheckedChangeListener listener = new OnCheckedChangeListener(){
public void onChackedChaged(RadioGroup group,int checkId){
RadioButton radioButton = (RadioButton) findViewById(checkedId);
String result = radioButton.getText().toString(); });}
(六)、CheckBox java.lang.Object ↳ android.view.View ↳ android.widget.TextView ↳ android.widget.Button ↳ android.widget.CompoundButton ↳ android.widget.CheckBox
CheckBox继承于Button,所以具有普通按钮的各种属性,但是与普通按钮不同的是, CheckBox提供了可选中的功能。

更多相关文章

  1. 【Android布局】在程序中设置android:gravity 和 android:layout
  2. 【Android布局】在程序中设置android:gravity 和 android:layout
  3. android:maxHeight,android:maxWidth失效
  4. Android中的Shape使用总结
  5. Android(安卓)TextView滚动的两种方案
  6. 【Android布局】在程序中设置android:gravity 和 android:layout
  7. Mono for Android(安卓)实现高效的导航
  8. 【Android布局】在程序中设置android:gravity 和 android:layo..
  9. Android(安卓)TextView文本的省略与显示

随机推荐

  1. Android标题栏、状态栏图标文字颜色及背
  2. Android(安卓)5.X新特性-Material Design
  3. Android应用程序自启动,已用于售卖机开机
  4. Android 帧动画
  5. Android(安卓)ToggleButton
  6. ANDROID 经典开源项目
  7. Android自定义组合控件
  8. android获取通讯录
  9. android使用actionbar与fragment
  10. android 酷欧天气完整项目