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 ...
随机推荐
- java集合系列之LinkList
概要 第1部分 LinkedList介绍第2部分 LinkedList数据结构第3部分 LinkedList源码解析(基于JDK1.6.0_45) 第5部分 LinkedList示例 转载请注明出处 ...
- Android之Android WebView常见问题及解决方案汇总
如有转载,请声明出处: 时之沙: http://blog.csdn.net/t12x3456 Android WebView常见问题解决方案汇总: 就目前而言,如何应对版本的频繁更新呢,又如何灵活多变 ...
- QThreadPool线程池的开发使用
QThreadPool+QRunnable线程池与QThread线程两种方式使用的场景不同,QThreadPool+QRunnable线程池主要用于那种不需要一直运行的任务,而QThread主要用于长 ...
- uva 10154 - Weights and Measures【dp】qi
题意:uva 10154 - Weights and Measures 题意:有一些乌龟有一定的体重和力量,求摞起来的最大高度.力量必须承受其上面包含自己的所有的重量. 分析:先按其能举起来的力量从小 ...
- Delphi的自动编译软件Want
Delphi自动编译环境的搭建及使用 什么是Want Want是一套Windows下用于编译Delphi源代码的工具.Want的名称是Windows Ant的意思. Ant是Java下最著名的自动编译 ...
- DELPHI NEXTGEN编译开关
DELPHI NEXTGEN编译开关 {$IFDEF NEXTGEN} UTF8String = type _AnsiString(65001); RawByteString = type _Ansi ...
- android的logcat详细用法!
from://http://www.miui.com/article-272-1.html [技术交流]android的logcat详细用法! logcat是Android中一个命令行工具,可以用于得 ...
- SharePoint SPUtility.SendEmail 发送邮件设置级别
前言 熟悉sharepoint开发的都知道,sharepoint默认有个发送邮件的方法,不过,最近有个需求,用户希望发送邮件的时候,带上邮件的级别. 经过研究,发现有下面的办法,可以添加邮件的发送级别 ...
- 新闻编辑室第一季/全集The Newsroom迅雷下载
第一季 The Newsroom Season 1 (2012)看点:频出佳剧的HBO这次将目光对准了新闻间这个话题多,故事更多的“小”地方.该剧讲述的是一家虚构的有线电视新闻网ACN的故事,由阿伦· ...
- 疑犯追踪第五季/全集Person of Interest迅雷下载
英文全名Person of Interest,第5季(2015)CBS.本季看点:<疑犯追踪>本季剧组暗示Finch可能重建机器,这次他会给机器更多自由(如Root一直要求的那样).或许新 ...