前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android点击Button实现切换点击图片效果的示例

Android点击Button实现切换点击图片效果的示例

作者头像
砸漏
发布2020-11-05 10:38:35
3.7K0
发布2020-11-05 10:38:35
举报
文章被收录于专栏:恩蓝脚本

这是一个简单的小的DEMO , 关于点击按钮用于实现图片的切换, 重要的就是里面的关于逻辑的处理, 在以后图片轮播的技术上关于逻辑的处理和这个类似

Android Button的点击事件切换点击图片

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity"  
  <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="184dp"
  android:background="@drawable/button_selector" / 
</RelativeLayout 

android:background=”@drawable/button_selector”

(2)在res文件夹下创建drawable文件夹,创建一个selector文件

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"? 
<selector xmlns:android="http://schemas.android.com/apk/res/android" 
  <item android:drawable="@drawable/q" android:state_pressed="true" </item 
  <item android:drawable="@drawable/w" android:state_focused="true" </item 
  <item android:drawable="@drawable/e" </item 
</selector 

文件夹内放三张图片用于切换的时候改变图片

(3)其他内容不需要改变

文件的图片随着按钮的点击变化

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对ZaLou.Cn的支持。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-09-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档