ImageView及其子类(二)
实例:强大的图片按钮
下面的实例定义了多个图片按钮,并定义了两个ZoomButton。两个ZoomButton的android:src属性分别指定为@android:drawable/btn_minus、@android:drawable/btn_plus,这样可以定义缩小和放大两个按钮。
下面是该实例的界面布局文件。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- 普通图片按钮 -->
<ImageButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/blue"/>
<!-- 按下时显示不同的按钮 -->
<ImageButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_selector" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10sp"
android:layout_gravity="center_horizontal">
<!-- 分别定义2个ZoomButton,并分别使用btn_munus和btn_plus图片 -->
<ZoomButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_zoom_down"
android:src="@android:drawable/btn_minus" />
<ZoomButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_zoom_up"
android:src="@android:drawable/btn_plus"/>
</LinearLayout>
<!-- 定义ZoomControls组件 -->
<ZoomControls android:id="@+id/zoomControls1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
<?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/red"/>
<!-- 指定按钮松开时的图片 -->
<item android:state_pressed="false" android:drawable="@drawable/purple" /> </selector>
上面布局文件的开头定义了两个ImageButton,第一个ImageButton的android:src指定为一张静态图片,这样无论用户有怎样的行为,该ImageButton总显示这张静态图片。第二个ImageBUtton的android:src指定为@drawable/button_selector,该Drawable组合了两张图片,可以保证用户单击该按钮时切换图片。
运行界面如下图:

ImageView及其子类(二)的更多相关文章
- ImageView及其子类
ImageView及其子类 (1)ImageView继承自View组件,任何Drawable对象都可以用ImageView来显示,ImageView派生出来了ImageButton.ZoomButto ...
- Android用户界面 UI组件--AdapterView及其子类(二) AdapterViewAnimator及其子类
AdapterViewAnimator:当在视图间切换时会显示动画. android:animateFirstView 定义ViewAnimation首次显示时是否对当前视图应用动画. android ...
- Android用户界面 UI组件--ImageView及其子类ImageButton,QuickContactBadge附带Draw9Patch工具说明
1.ImageView 常用属性: android:src 设置可绘制对象作为 ImageView 显示的内容 android:cropToPadding 如果设置为true,图片裁剪到保留该Imag ...
- ImageView的子类无法加载图片
在图片预览时,偶现图片无法现实,在查看程序的时候发现Bitmap是实际存在的,但是在ImageView中缺绘制不出来,这个问题困然了我很久,查看代码也查不出原因,再加上是偶现的,查原因时费了不少时间. ...
- ImageView及其子类(三)
实例:使用QuickContactBadge关联联系人 QuickContactBadge继承了ImageView,因此它的本质也是图片,也可以通过android:src属性指定他显示的图片 ...
- ImageView及其子类(一)
ImageView继承自View组件,它的主要功能是用于显示图片——实际上这个书法不太严谨因为他能显示的不仅是图片,任何Drawable对象都可以使用ImageView来显示.除此之外,ImageVi ...
- Android用户界面 UI组件--TextView及其子类(二) Button,selector选择器,sharp属性
1.XML文件中的OnClick 属性可以指定在Activity中处理点击事件的方法,Activity中必须定义该属性指定的值作为方法的名字且有一个View类型的参数,表示此物件被点击. 2.使用se ...
- Android零基础入门第22节:ImageView的属性和方法大全
原文:Android零基础入门第22节:ImageView的属性和方法大全 通过前面几期的学习,TextView控件及其子控件基本学习完成,可以在Android屏幕上显示一些文字或者按钮,那么从本期开 ...
- 疯狂Android讲义 - 学习笔记(二)
Android应用的用户界面编程 2.1 界面编程与视图(View)组件 Android应用的绝大部分UI组件放在android.widget.android.view包及其子包中,所有UI组件都继承 ...
随机推荐
- IE6 7 父级元素的overflow:hidden 是包不住子级的relative
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 转:Loadrunner上传文件解决办法(大文件)
最近再做一个跟海量存储相关的项目测试,需要通过LR模拟用户大量上传和下载文件,请求是Rest或Soap,同时还要模拟多种大小尺寸不一的文件 通常情况下,都是使用简单的post协议即可: 方法一: we ...
- PAT (Advanced Level) 1065. A+B and C (64bit) (20)
因为会溢出,因此判断条件需要转化.变成b>c-a #include<cstdio> #include<cstring> #include<cmath> #in ...
- css3新增的background属性
1.background-size 可取值:auto(背景图片正常显示) size size (150px 40%) cover (背景图片覆盖整个背景) contain(背景图片缩小填满整个背景) ...
- base库插件---form
$().extend('serialize', function () { for (var i = 0; i < this.elements.length; i ++) { var form ...
- Android音频系统之音频框架
1.1 音频框架 转载请注明,From LXS, http://blog.csdn.net/uiop78uiop78/article/details/8796492 Android的音频系统在很长一段 ...
- @media max-width 与jquery宽度取值的差异
最近写了个响应式网站,有些效果通过用jq的$(window).width()来判断屏幕宽度,当屏幕宽度小于1366时一些参数发生变化.@media中也有小于1366的判断条件,但是用起来的时候发现一个 ...
- uwsgi性能调忧
摘要:调大uwsgi配置中 listen=1024的数目是提高并发能力最有效的办法.第二种方法是调大processes数目 发现总是超时报警 1 使用ab确定网络具体征况 [bre@dmp-1 ~] ...
- Python之路【第三篇】:模块
定义: 包:包含__init__.py文件.模块(也是.py文件) 当包被其它模块调用时,首先会执行该包下的__init__文件 包含有模块,包可以有多级 模块的导入: import from...i ...
- Mycat 安装配置
下载https://github.com/MyCATApache/Mycat-download Mycat 需要jdk 环境,首先安装 jdk 安装完 jdk 环境以后 下载 mycat server ...