Android ImageButton简介

Android ImageButton使用详解(系列教程四) Android ImageButton使用详解。 阅读详情

Button按钮上显示文字

ImageButton上则显示图片,为它指定android:text属性没用。可以指定android:src属性,可以使用静止图片或Drawable对象。


ImageButton派出了一个ZoomButton,可以代表放大、缩小两个按钮。默认提供了btn_minus、btn_plus两个Drawable资源。

Android还提供了一个ZoomControls组件,相当于同时组合了放大、缩小两个按钮,并允许分别为两个按钮绑定不同的事件监听器。


activity_main.xml文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >                  
   
    <!-- 普通图片按钮 -->
    <ImageButton 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/red"
        />
    
    <!-- 按下时显示不同图片的按钮 -->
    <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="10dp"
        android:layout_gravity="center_horizontal"
        >
        <!-- 分别定义2个ZoomButton,分别使用btn_minus和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/zoomControls"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            />
    
</LinearLayout>

red.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
    
    <size 
        android:width="200dp"
        android:height="100dp"
        />
    
    <solid android:color="#CC0001"/>
</shape>

my_button_pressed.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
    
    <size 
        android:width="100dp"
        android:height="100dp"
        />
    <!--圆角半径 -->  
    <corners   
        android:topLeftRadius="10dp"  
        android:topRightRadius="10dp"  
        android:bottomLeftRadius="10dp"  
        android:bottomRightRadius="10dp"  
        />  
      
    <!-- 背景颜色 -->  
    <solid android:color="#B4CDE6"/>  
      
    <!-- 描边 -->  
    <stroke   
        android:width="2dp"  
        android:color="#000"  
        />  
      
    <!-- 内边距 -->  
    <padding   
        android:left="10dp"  
        android:right="10dp"  
        android:top="10dp"  
        android:bottom="10dp"  
        /> 

</shape>

my_button_default.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"
    >
    
    <size 
        android:width="100dp"
        android:height="100dp"
        />
    
    <!--圆角半径 -->  
    <corners   
        android:topLeftRadius="10dp"  
        android:topRightRadius="10dp"  
        android:bottomLeftRadius="10dp"  
        android:bottomRightRadius="10dp"  
        />  
      
    <!-- 背景颜色 -->  
    <solid android:color="#4F71AE"/>  
      
    <!-- 描边 -->  
    <stroke   
        android:width="2dp"  
        android:color="#000"  
        />  
      
    <!-- 内边距 -->  
    <padding   
        android:left="10dp"  
        android:right="10dp"  
        android:top="10dp"  
        android:bottom="10dp"  
        /> 
    

</shape>

效果如图:


Android中ImageButton的用法 android 开发中的高级控件,ImageButton网上资源视频教程源码 立即下载

相关推荐

Quartus II 13.1 出现 ‘‘can‘t find design entity <Filename>‘‘ 问题的解决方法

Quartus II 13.1 出现 ''can't find design entity '' 问题的解决方法

qq_62076686的博客 1万+

Android 图像按钮ImageButton

ImageButton派生自ImageView,而不是Button,这一点当第一眼看到ImageButton的时候,我就下意识的认识它是Button的子类。所以ImageButton拥有ImageView的属性和方法,不过ImageView有默认的按钮外观。 从android文档中,我们可以很清楚看到ImageButton和ImageView之间的关系。 让我们在看下ImageButton和Im

秋殇阁 3万+

南京银行信息技术岗提前批笔试与面试

1、笔试 笔试大致可以分为三部分:性格测试、行测题目、专业知识 性格测试 性格测试一般会有较多的体量,可能一共大概有一百多道接近两百道的样子,这个是不限时的。 前面有100道是这样的题目,就是有四个选项都是各种形容词,然后分别选出最符合自己的与最不符合自己的选项。这种题你就顺着自己的潜意识填就行了,但是前后要一致,我怀疑他出这么多题,可能就是考一考你记不记得前面填了啥。比如你做到第90题的时候,可能会出现和前面第2题类似的四个形容词,更有甚者就是一模一样的,你要对自己之前选的什么有个比较清楚的记忆。

qq_40971025的博客 6922

Android 基础知识4-3.3 Button(按钮)与ImageButton(图像按钮)详解

StateListDrawable是Drawable资源的一种,可以根据不同的状态,设置不同的图片效果,关键节点,我们只需要将Button的background属性设置为该drawable资源即可轻松实现,按下 按钮时不同的按钮颜色或背景!drawable:引用的Drawable位图,我们可以把他放到最前面,就表示组件的正常状态~:是否获得焦点:是否获得窗口焦点:控件是否可用:控件可否被勾选,eg:checkbox:控件是否被勾选:控件是否被选择,针对有滚轮的情况:控件是否被按下。

yyxhzdm的博客 2341

别再被网站风控了!手把手教你修改Chromium源码,实现TLS指纹随机化

本文详细介绍了如何通过修改Chromium源码实现TLS指纹随机化,有效规避网站风控。文章深入解析了TLS指纹(如JA3指纹)的工作原理,并提供了具体的源码修改步骤和编译方法,帮助开发者突破高级反爬技术。通过动态打乱加密套件顺序,实现每次请求生成不同的指纹,显著提升自动化工具的隐蔽性。

weixin_28712661的博客 427

3GPP Release与UE Category:无线通信标准演进与终端能力分级全解析

在蜂窝移动通信领域,技术标准的演进与终端设备的能力分级是理解整个产业发展的核心框架。其基本原理由国际标准组织3GPP通过周期性发布的技术规范版本(Release)来定义,每个Release都像一份阶段性的技术蓝图,规定了网络与终端应支持的新功能与性能基线。这种标准化机制的技术价值在于确保了全球设备的互联互通与网络的平滑升级,为从4G LTE到5G NR乃至未来的演进提供了清晰路径。在这一框架下,终端能力分级(如LTE时代的UE Category)是将标准转化为具体设备性能的关键环节,它直接定义了终端在射频和

weixin_34098209的博客 331

15. 【Android教程】按钮 Button/ImageButton

在前面两章我们讲了 TextView,它是一个纯输出的控件;而 EditText 在 TextView 基础之上加入了简单的输入功能;今天要讲的 Button 是一个和用户互动感很强的控件,从今往后不再是单纯的文本展示,我们可以通过 TextView、EditText 再加上 Button 做出非常多有很意思的功能。ImageButton 可以理解为是 Button 的升级版,它在后者的基础之上加上了图片背景,使用方式和 Button 类似。

这是一个web全栈开发的博客,取其精华去其糟粕,争取让大家一看就懂,一学就会,一用就成~ 2147

微信小程序推送微信服务号模板消息

微信小程序中发送微信服务号模板消息,无需用户手动确认订阅,无需绑定开放平台,无需使用UnionId。

qq_20751269的博客 1556

Android应用开发(9)图像按钮(ImageButton)(暂存)

Android应用开发(9)图像按钮(ImageButton)

zsyf33078的专栏 1734

KubeVela入门到精通-K8S多集群交付

KubeVela是一个功能强大、易于使用、高度可扩展的应用交付与管理平台。它基于Kubernetes和OAM 技术构建,通过开放应用模型(OAM)来作为顶层的抽像,提供了声明式部署、多集群/混合环境支 持、插件与扩展性、中心化管控以及易于使用与可观测性等特点。

小杨同学的博客 1269

RK3568笔记六十一:MIPI摄像头应用程序编写

V4L2设备驱动框架向应用层提供了一套统一、标准的接口规范,应用程序按照该接口规范来进行应用编程,从而使用摄像头。对于摄像头设备来说,其编程模式如下所示:1.首先是打开摄像头设备;2.查询设备的属性或功能;3.设置设备的参数,譬如像素格式、帧大小、帧率;4.申请帧缓冲、内存映射;5.帧缓冲入队;6.开启视频采集;7.帧缓冲出队、对采集的数据进行处理;8.处理完后,再次将帧缓冲入队,往复;9.结束采集。

1004

Android ImageButton 使用详解

ImageButton 是 Android 中专门用于显示图片按钮的控件,它继承自 ImageView,但具有按钮的点击特性。下面我将全面介绍 ImageButton 的使用方法。通过合理使用 ImageButton,可以创建直观、美观且功能完善的图标按钮,提升应用的用户体验。创建 selector 资源文件 (方法一:使用 CardView 包裹。方法二:使用自定义背景。

百锦再的博客 1万+

基于Simulink的电机驱动逆变器仿真

本文完成了电机驱动逆变器的Simulink多层级仿真平台搭建,实现了:✅ 构建了从理想到器件级的逆变器模型体系✅ 实现了Si/SiC损耗精确计算与结温预测✅ 建模了母线寄生参数、死区效应、栅极驱动等关键非理想特性✅ 支持故障注入与保护策略验证✅ 集成了热管理、EMI、寿命预测与碳足迹评估。

amy_mhd的博客 87

Android-ImageButton的使用

<br />ImageButton是上面带有图片的Button,与Button只用类似<br /> <br />第一步:<br />首先找到两个图标,在res目录下创建一个名为drawable的文件夹,将图片放入其中<br /> <br />第二步:<br />编写main.xml文件,如下<br /> <br /><?xml version="1.0" encoding="utf-8"?><br /><LinearLayout xmlns:android="http://schemas.android.c

花郎的专栏 2万+

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Android ImageButton示例

在Android中,您可以使用“ android.widget.ImageButton ”显示具有自定义背景图片的常规“ Button ”。 在本教程中,我们向您展示如何显示一个带有名为“ android_button.png ”的背景图像的按钮,当用户单击它时,显示一条短消息。 就如此容易。 注意 您可能还喜欢这个Android ImageButton选择器示例 ,该示例允许根据按钮...

一名可爱的技术搬运工 2860

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Android studio中单击ImageButton按钮变换图片或颜色

Android studio中单击ImageButton按钮变换图片或按钮

wljaz的博客 9369

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

android中的ImageButton

随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666) /* * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Versi...

孤云博客 1865

Android安卓开发基础-Button与ImageButton

介绍安卓控件Button及ImageButton在java文件及xml文件中的使用(主要以Button为例)

weixin_53743049的博客 1168

杂乱之android的ImageButton应用

先上图:(图中为两个按钮,可不是两个图片,嘿嘿)第一个按钮为ImageButton,第二个按钮为Button。imagebutton.xml代码

梦中一夜下江南 4371

android imagebutton的使用

ImageButton是上面带有图片的Button,与Button只用类似 第一步: 首先找到两个图标,在res目录下创建一个名为drawable的文件夹,将图片放入其中 第二步: 编写main.xml文件,如下 http://schemas.android.com/apk/res/android"     android:orientation="vertical"

路遥知马力 1398

Android studio 013 ImageButton 图片按钮

复制两个图片到mipmap中 第一步 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" ...

weixin_33595571的博客 2995

Android Imagebutton 动态修改图片

睁眼闭眼图片自取:https://pan.baidu.com/s/1dAXOys91Jufl0566K0fGvw 密码:8sjc 图片资源来源:https://blog.youkuaiyun.com/qq_33072593/article/details/53749320 下面是我的代码和效果: 效果如下: Xml文件: <ImageButton android:l...

阳光大男孩!!!的博客 3298

Android基础(一) ImageButton

图片按钮(ImageButton)可以根据当前按钮状态来显示不同的图片。1. 一般通过在节点里设置android:src属性来进行显示设置图片源。2. 若想去掉原来按钮的背景,则通过设置图片背景为透明实现。(android:background="#00000000")

stefzeus的专栏 1万+

9、从头学Android之Button和ImageButton

Button 类结构图: 由类结构图,可以看出Button是继承于TextView的,所以TextView的一些属性也适用于Button控件。对于Button控件,相信大多数开发人员是再熟悉不过了,那么废话不多说,直接应用实践吧   实践演练: 1、  如何设置按钮

90worker 2万+

Android的ImageButton不能显示文字

很多人对 Android提供的ImageButton有个疑问,当显示Drawable图片时就不会再显示文字了,其实解决的方法有三种: 第一种:就是图片中就写入文字,但是这样解决会增加程序体积,同时硬编码方式会影响多国语言的发布。 第二种:解决方法很简单,通过分析可以看到ImageButton的 layout,我们可以直接直接继承,添加一个TextView,对齐方式为右侧即可实现Imag

zsb190623的专栏 1万+
上一篇: Android EditText用户友好的输入界面
下一篇: Android QuickContactBadge
KingLearnJava
博客等级 码龄12年 93粉丝 84原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值