首页 > 技术文章 > Android基本组件是什么?

weiichuangwangxun 2018-11-28 14:47 原文

1ImageView继承View组件,不单单用于显示图片,用 XML代码 编写的Drawable也可以显示出来。
其中的XML属性 android:scaleType(设置图片如何缩放或移动以适应ImageView的大小) 有很多的属性值,如:matrix(使用矩形方式进行缩放)fitXY(对图片横向`纵向缩放)center(图片放在ImageView中间)等等…
下面是XML代码:<ImageViewandroid:id="@+id/imageView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/textView1"android:scaleType="fitCenter"android:src="@drawable/ic_launcher"android:layout_toRightOf="@+id/textView1" />

 

2、ImageButton,与前面讲的Button的区别在于Button生成的按钮上显示文字,而ImageButton显示图片,对它设置android:text属性是没用的。
下面是XML代码:使用android:src 自定义Drawable对象<ImageButtonandroid:id="@+id/imageButton1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/button_selector" />补充:drawable的XML文件在前面的笔记(二)也有写过Android基本组件(笔记二)<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" ><!– 指定按钮按下时的图片 –><item android:state_pressed="true"android:drawable="@drawable|d1"/><!– 指定按钮松开时的图片 –><item android:state_pressed="false"android:drawable="drawable|d2"/></selector>

 

3、ZoomButton代表“放大”,“缩小”两个按钮,android默认提供了btn_minus,btn_plus两个drawable资源。<ZoomButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/btn_zoom_down"android:src="@android:drawable/btn_minus" /><ZoomButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/btn_zoom_up"android:src="@android:drawable/btn_plus" />Android基本组件(三)

 

4、QuickContactBadge,继承了ImageView,可通过android src 添加图片。增加的额外功能是该图片可以关联到手机中指定的联系人,当用户点击该图片时系统将会打开相应联系人的联系方式界面。<QuickContactBadgeandroid:id="@+id/badge"android:layout_height="wrap_content"android:layout_width="wrap_content"android:src="@drawable/ic_launcher"/>


转载 - 编程知识

推荐阅读