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

刚开始看到这种效果很是好奇,不知道是怎么实现的,后来仔细一想,应该是整个啤酒罐是一张图片(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>

  搞定。

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. js code

    //在页面增加一个放置图标的区块 if(!document.getElementById('_span_jiucuo')) document.write("<span id='_spa ...

  2. 对前台传过来的实体是否为空 进行为空校验的N种方法

    首先定义一个注解,如下 import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import j ...

  3. C#连接数据库open函数失败

    错误信息:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接. (provider ...

  4. [转][linux]简单的linux下的tcp/udp

    转自:https://blog.csdn.net/cabing2005/article/details/53068880 详细函数以及参数解释请看原链接. windows下的tcp/udp参考:htt ...

  5. 优雅地记录Python程序日志1:logging模块简介

    本文摘自:https://zhuanlan.zhihu.com/p/31893724 本篇涉及: logging模块的调用: 保存log日志为文件: 调整输入日志等级: 修改日志消息格式: 前言 在使 ...

  6. 第 8 章 容器网络 - 059 - 安装配置 flannel

    安装配置 flannel 1) build flannel flannel 没有现成的执行文件可用,必须自己 build,最可靠的方法是在 Docker 容器中 build. 不过用于做 build ...

  7. photoshop怎么旋转图片

    Adobe Photoshop 是一款为人熟知的功能强大的图像处理软件.在这里简单介绍一下如何在photoshop里进行图像的旋转. 工具/原料   Adobe Photoshop 软件,图像一张 方 ...

  8. PhantomJS框架(初识无头浏览器)

    博主今天看到大神聊起 headless,首先我去了解了下这个概念  无头浏览器 selenium框架是有头浏览器的代表,即可看得见的浏览器 而headless browser无头浏览器,即看不见的浏览 ...

  9. C# 网页图片采集

    http://blog.csdn.net/a237428367/article/details/5987832 using System; using System.Collections.Gener ...

  10. WPF触发器(Trigger)

    WPF触发器(Trigger.DataTrigger.EventTrigger) WPF中有种叫做触发器的东西(记住不是数据库的trigger哦).它的主要作用是根据trigger的不同条件来自动更改 ...