Android -- isInEditMode
解释
Indicates whether this View is currently in edit mode. A View is usually in edit mode when displayed within a developer tool. For instance, if this View is being drawn by a visual user interface builder, this method should return true. Subclasses should check the return value of this method to provide different behaviors if their normal behavior might interfere with the host environment. For instance: the class spawns a thread in its constructor, the drawing code relies on device-specific features, etc. This method is usually checked in the drawing code of custom widgets.
如果在自定义控件的构造函数或者其他绘制相关地方使用系统依赖的代码,会导致可视化编辑器无法报错并提示:Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
code
public class LockRelativeLayout extends RelativeLayout {
private Handler mainHandler = null; //与主Activity通信的Handler对象 public LockRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs, 0);
mContext = context;
if (isInEditMode()) { return; }
mainHandler = ((MainActivity)mContext).getMHandler();
}
}
如果不加上if (isInEditMode()) { return; },标红处代码会导致可视化编辑报错
我是天王盖地虎的分割线
http://stackoverflow.com/questions/15423149/how-to-use-isineditmode-to-see-layout-with-custom-view-in-the-editor
Android -- isInEditMode的更多相关文章
- android窗口泄漏,isInEditMode解决可视化编辑器无法识别自定义控件的问题
android窗口泄漏 在做项目是遇到这个错误:google:WindowManager: Activity has leaked window. 产 生原因:我们知道Android的每一个Activ ...
- Android Weekly Notes Issue #236
Android Weekly Issue #236 December 18th, 2016 Android Weekly Issue #236 本期内容包括: Google的物联网平台Android ...
- 让低版本的 Android 项目显示出 Material 风格的点击效果
每天都被不同的需求纠缠的生活是幸福而又不幸的,这不我们家亲爱的设计师们又让我们在低版本的 Android 平台上实现一下类似于 Material Design 的点击效果. 虽然大家都知道 Mater ...
- Android Lint Checks
Android Lint Checks Here are the current list of checks that lint performs as of Android Studio 2.3 ...
- [Android] 升级了新的android studio之后 发生如下的报错,The following classes could not be instantiated:
The following classes could not be instantiated:- android.support.v4.widget.DrawerLayout (Open Class ...
- android常见问题(一)
一:文本的颜色选择器: 在res目录下面创建color文件夹,在color文件夹下面创建font_style_colors.xml文件<?xml version="1.0" ...
- android 5.0 水波纹 实现
1. 定义一个普通圆角背景的xml; rounded_corners.xml <?xml version="1.0" encoding="utf-8"?& ...
- Android 开源项目PhotoView源码分析
https://github.com/chrisbanes/PhotoView/tree/master/library 这个就是项目地址,相信很多人都用过,我依然不去讲怎么使用.只讲他的原理和具体实现 ...
- Android ViewFlow的一个例子
完成这个例子的步骤: 1.下载ViewFlow的源码,然后将类ViewFlow放在自己的工程的src的某个包下. 2.下载的源码里有2个工程view flow,viewflow-example.将vi ...
随机推荐
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C. Table Tennis Game 2 水题
C. Table Tennis Game 2 题目连接: http://codeforces.com/contest/765/problem/C Description Misha and Vanya ...
- request.getRequestDispatcher("").forward()中文乱码
即使jsp页面的编码已设为“UTF-8”,有中文的地方还是会出现乱码,但是用response.sendRedirect不会出现此问题. 解决方案一: 不使用PrintWriter out=respon ...
- 解决 PermGen space Tomcat内存设置(转)
在使用Java程序从数据库中查询大量的数据或是应用服务器(如tomcat.jboss,weblogic)加载jar包时会出现java.lang.OutOfMemoryError异常.这主要是由于应用服 ...
- STM32F4 SPI with DMA
STM32F4 SPI with DMA A few people have requested code, so I thought I’d post the code showing how I’ ...
- ARM Memory Copy
MODULE ARM_MEMORY PUBLIC ARM_MEMCPY PUBLIC ARM_MEMSET PUBLIC ARM_MEMSET8 PUBLIC ARM_MEMSET16 PUBLIC ...
- systemtap跟踪C
1.[root@localhost ~]# rpm -qi glibcName : glibc Relocations: (not rel ...
- CentOS内核定制
版本号:1.0.1 作者:石硕 更新:2014-05-09 15:04:53 ============================================================ ...
- Flex Viewer(二) 体系结构
一.概述 在上一篇文章<深入浅出Flex Viewer (一)——概述>中,笔者对Flex Viewer用于构建以地图为中心的富客户端(RIA)应用的原型的功能和价值做了简要地介绍.在本文 ...
- [EF Core]数据迁移(二)
摘要 在实际项目中,大多都需要对业务逻辑以及操作数据库的逻辑进行分成操作,这个时候该如何进行数据的迁移呢? 步骤 上篇文章:EF Core数据迁移操作 比如,我们将数据上下文放在了Data层. 看一下 ...
- [Winform]setupfactory打包时添加开机自启动的脚本
摘要 如果有这样的需求,需要软件开机自启动,该如何做呢?开机自启动的做法,就是修改注册表,将你的exe注册到注册表Run节点下. setupfactory 在安装的时候需要以管理员身份运行,这样可以保 ...