注意图中我画的箭头,当时鼠标点击的黑色圈圈的位置,然后按钮出现了按下的效果(黄色的描边)

刚开始看到这种效果很是好奇,不知道是怎么实现的,后来仔细一想,应该是整个啤酒罐是一张图片(ImageView),该图片是布局在三个按钮之上,然后就是最关键的地方,把图片设置为不可获取焦点,也就是android:focusable="false" ,就这样简单的一行,就可以搞定了!

main.xml:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. >
  6. <LinearLayout
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content"
  9. android:orientation="vertical" >
  10. <Button
  11. android:layout_width="match_parent"
  12. android:layout_height="wrap_content"
  13. android:layout_margin="10dp"
  14. android:text="button1"
  15. android:background="@drawable/button_selector"
  16. />
  17. <Button
  18. android:layout_width="match_parent"
  19. android:layout_height="wrap_content"
  20. android:layout_margin="10dp"
  21. android:text="button2"
  22. android:background="@drawable/button_selector"
  23. />
  24. <Button
  25. android:layout_width="match_parent"
  26. android:layout_height="wrap_content"
  27. android:layout_margin="10dp"
  28. android:text="button3"
  29. android:background="@drawable/button_selector"
  30. />
  31. </LinearLayout>
  32. <ImageView
  33. android:layout_width="wrap_content"
  34. android:layout_height="wrap_content"
  35. android:src="@drawable/bg2"
  36. android:focusable="false"
  37. />
  38. </RelativeLayout>

  button_selector.xml:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector
  3. xmlns:android="http://schemas.android.com/apk/res/android">
  4. <item android:state_pressed="true" >
  5. <shape>
  6. <!-- 实心,即填充 -->
  7. <solid android:color="#8470FF"/>
  8. <!-- 描边 -->
  9. <stroke
  10. android:width="2dp"
  11. android:color="#FFFF00"/>
  12. <!-- 圆角 -->
  13. <corners
  14. android:radius="5dp" />
  15. <padding
  16. android:left="10dp"
  17. android:top="10dp"
  18. android:right="10dp"
  19. android:bottom="10dp" />
  20. </shape>
  21. </item>
  22.  
  23. <item>
  24. <shape>
  25. <!-- 实心,即填充 -->
  26. <solid android:color="#8470FF"/>
  27. <corners
  28. android:radius="5dp" />
  29. <padding
  30. android:left="10dp"
  31. android:top="10dp"
  32. android:right="10dp"
  33. android:bottom="10dp" />
  34. </shape>
  35. </item>
  36. </selector>

  搞定。

view的focusable属性改变设置是否可获取光标的更多相关文章

  1. [BS-16] 尽量将View的Opaque属性设置为YES(默认就是YES)

    尽量将View的Opaque属性设置为YES(默认就是YES) UIView控件都有一个Opaque属性,如果不会更改view的透明度,那么应该将其opaque属性设置为YES.为什么要这样做呢?其实 ...

  2. Android绘图机制(一)——自定义View的基础属性和方法

    Android绘图机制(一)--自定义View的基础属性和方法 自定义View看起来,确实看起来高深莫测,很多Android开发都不是特别在行这一块,这里面的逻辑以及一些绘画都是有一点难的,说一下我目 ...

  3. View动画和属性动画

    在应用中, 动画效果提升用户体验, 主要分为View动画和属性动画. View动画变换场景图片效果, 效果包括平移(translate), 缩放(scale), 旋转(rotate), 透明(alph ...

  4. 查看特定View的默认属性值

    当我在分析focus.touch事件处理代码时发现,有些属性对代码的逻辑有非常重要的影响,比如clickable.focusable 这些属性.这时我们自然而然的想到,那么这些属性的默认值是什么呢?在 ...

  5. js 实现angylar.js view层和model层双绑定(改变view刷新 model,改变model自动刷新view)

    近段时间研究了下angular.js 觉得它内部实现的view和model层之间存在很微妙的关系,如下图 如上图说的,view的改变会update 数据层model, 数据层会update视图层vie ...

  6. Android中focusable属性的妙用——底层按钮的实现

    http://www.cnblogs.com/kofi1122/archive/2011/03/22/1991828.html http://www.juziku.com/weizhishi/3077 ...

  7. 使用CSS3的appearance属性改变元素的外观

    昨天在和同事一起完成项目的时候,我使用了appearance来渲染select,但是在firefox下出现问题,不完美,最后去除了.但还是要学习下这个属性.大家都知道每个浏览器对HTML元素渲染都不一 ...

  8. CSS3的appearance属性--改变元素的外观

    CSS3 appearance 属性 CSS 参考手册 实例 使 div 元素看上去像一个按钮: div { appearance:button; -moz-appearance:button; /* ...

  9. DBGrid 各属性的设置

    在 Delphi 语言的数据库编程中,DBGrid 是显示数据的主要手段之一.但是 DBGrid 缺省的外观未免显得单调和缺乏创意.其实,我们完全可以在我们的程序中通过编程来达到美化DBGrid 外观 ...

随机推荐

  1. centos nginx 中安装ssl证书 以及在项目中的使用

    今天阿里云的证书到期了,重新申请了一个,下面是从申请到安装以及结合项目使用的过程: 1.登录阿里云   2.在左侧找到SSL证书 3.申请免费的证书 4.下载证书 5.根据说明配置nginx 6.在项 ...

  2. synchronized和volatile

    迄今为止,看到的最清楚的一篇: https://zhuanlan.zhihu.com/p/29866981 volatile https://zhuanlan.zhihu.com/p/34362413

  3. VS2010_慢

    ZC:IntelliSense 一旦关闭,代码提示 也就没有了... ZC:IntelliSense 和 IntelliTrace,不是一个东西... 1.http://blog.csdn.net/c ...

  4. ES6的新API如Promise,Proxy,Array.form(),Object.assign()等,Babel不能转码, 使用babel-polyfill来解决

    Babel默认只转换新的JavaScript句法(syntax),而不转换新的API,比如Iterator.Generator.Set.Maps.Proxy.Reflect.Symbol.Promis ...

  5. RxJava + Retrofit

    一.添加依赖 compile 'io.reactivex:rxandroid:1.2.0' compile 'io.reactivex:rxjava:1.1.5' compile 'com.googl ...

  6. 人脸识别ArcfaceDemo for Windows 分享

    Demo_for_Windows https://github.com/ArcJonSnow/Demo_for_Windows Arcsoft ArcfaceDemo for Windows, VS2 ...

  7. Mac python3.6 安装即使用 psycopg2

    学习下python调用PostgreSQL数据库 首先需要安装 psycopg2 python3安装: pip install psycopg2-binary 官网地址: https://pypi.o ...

  8. C# ---- GC中代的递增规律

    只有当对象所在代被 Collect 了,改对象所在代才会加 1 ,代值最大为 2 示例1: using System; namespace myMethod { class People{} clas ...

  9. linux中tar命令(打包、压缩、解压)、zip和unzip、rar多种压缩文件

    一.名词解释 打包:将一大堆文件或目录变成一个总的文件[tar命令] 压缩:将一个大的文件通过一些压缩算法变成一个小文件[gzip,bzip2等] Linux中很多压缩程序只能针对一个文件进行压缩,这 ...

  10. SpringBoot集成TkMybatis插件 (二)

    一.Tkmybatis的好处 Tkmybatis是在mybatis框架的基础上提供了很多工具,让开发更加高效.这个插件里面封装好了我们需要用到的很多sql语句,不过这个插件是通过我们去调用它封装的各种 ...