2019独角兽企业重金招聘Python工程师标准>>>

看到百威啤酒的客户端主界面的按钮,感觉比较新奇,先看下图片:

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

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

为了验证我的想法,我建了一个工程来做测试,效果如下图所示:

具体代码如下:

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="button1" android:background="@drawable/button_selector" />    <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="button2" android:background="@drawable/button_selector" />  <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="button3" android:background="@drawable/button_selector" />  </LinearLayout> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/bg2" android:focusable="false" />
</RelativeLayout>

button_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" > <shape> <!-- 实心,即填充 --> <solid android:color="#8470FF"/> <!-- 描边 --> <stroke android:width="2dp" android:color="#FFFF00"/> <!-- 圆角 --> <corners android:radius="5dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item><item>       <shape> <!-- 实心,即填充 --> <solid android:color="#8470FF"/> <corners android:radius="5dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item>
</selector>

转载于:https://my.oschina.net/u/1036767/blog/213979

Android中focusable属性的妙用——底层按钮的实现相关推荐

  1. android中各属性布局,Android里面各布局的属性定义

    LinearLayout(线性布局) 提供了控件水平垂直排列的模型,同时可以通过设置子控件的weight布局参数控制各个控件在布局中的相对大小. 水平(vertical) 垂直(horizontal) ...

  2. Android中shape属性详解

    一.简单使用 刚开始,就先不讲一堆标签的意义及用法,先简单看看shape标签怎么用. 1.新建shape文件 首先在res/drawable文件夹下,新建一个文件,命名为:shape_radius.x ...

  3. 在CSS中clear属性的妙用

    这里向大家描述一下在CSS中clear属性妙用,图片和文字元素出现在另外元素中,那么它们(图片和文字)可称为浮动元素(floatingelement).使用clear属性可以让元素边上不出现其它浮动元 ...

  4. android中textview记录日志,Android中TextView属性全纪录

    关于TextView TextView是Android开发中最最常见的控件之一,在API记录的属性有很多,但实际开发中,有很多很少涉及但是却非常有用的属性,值得去尝试,所以记录下来,既可以给大家提供参 ...

  5. android中textcolor属性,android – EditText和TextView textColorPrimary不遵循API lt;21的主题颜色...

    在设计工具栏视图以使其适用于API 21及以下版本时存在一些问题,但我认为我有这个styles.xml @color/colorPrimary @color/colorPrimaryDark @col ...

  6. android中edittext属性

    EditText继承关系:View-->TextView-->EditText EditText的属性很多,这里介绍几个: android:hint="请输入数字!"/ ...

  7. Android中visibility属性VISIBLE、INVISIBLE、GONE的区别

    在Android开发中,大部分控件都有visibility这个属性,其属性有3个分别为"visible "."invisible"."gone&quo ...

  8. android中edittext属性,Android中EditText的inputType属性的详解

    xml的inputtype的值. Android:inputType="none" android:inputType="text" android:input ...

  9. JAVA中的visible什么意思_详解Android中visibility属性VISIBLE、INVISIBLE、GONE的区别

    在Android开发中,大部分控件都有visibility这个属性,其属性有3个分别为"visible "."invisible"."gone&quo ...

最新文章

  1. (完全解决)Dataframe的赋值问题SettingWithCopyWarning: A value is trying to be set on a copy of a slice
  2. 量子力学与机器学习相结合,预测高温下的化学反应
  3. delphi html table,delphi 使用webbrowser取得网页中表格(Table)内容的正确方法
  4. 如何查看mysql my.ini_MySQL学习笔记(一)
  5. 今天开通一个真正属于自己的博客了《L.M》
  6. MediaPlayer 播放视频的方法
  7. linux视频在windows播放器,适用于Windows和Linux的免费多媒体播放器SMPlayer 18.6.0发布 - 爱绿豆...
  8. Web前端笔记-element ui中table中某列添加a便签进行跳转
  9. maven清理缓存_mybatis源码初探【二】缓存的实现
  10. Teamcenter(Enterprise 2007) Admin 手法之 -- 移除relation
  11. CentOS 8安装Redis的两种方式
  12. buuct 假如给我三天光明 misc_假如给我三天光明读后感
  13. python 防破解_Python 程序员如何防止数据被修改?
  14. Fortran与C/C++混合编程示例
  15. AssetPostprocessor.OnPreprocessModel
  16. 他是中国最牛X的黑客,曾让6个国家束手无策,却被怀疑是精神病
  17. linux ios开发环境,iOS开发环境搭建(Linux版)
  18. Python selenium —— selenium与自动化测试成神之路
  19. 京东到家大数据平台架构演进实战
  20. Android 实现定位

热门文章

  1. java byte缓存_Java 之 字节缓冲流
  2. exfat最佳单元大小_047|仓储物流自动化系统中的物料单元
  3. 解决swiper在tab切换时,swiper不生效,以及display:none后,无法自动滑动的问题
  4. vue中create 什么触发_vue中eventbus被多次触发(vue中使用eventbus踩过的坑)
  5. SpringMVC学习03之使用注解开发SpringMVC
  6. Mybatis框架的操作步骤和细节处理
  7. Python_基础_6
  8. 15.基于Hadoop的数据仓库Hive第2部分
  9. CNN应用之基于R-CNN的物体检测-CVPR 2014-未完待续
  10. 【面向代码】学习 Deep Learning Convolution Neural Network(CNN)