解释

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的更多相关文章

  1. android窗口泄漏,isInEditMode解决可视化编辑器无法识别自定义控件的问题

    android窗口泄漏 在做项目是遇到这个错误:google:WindowManager: Activity has leaked window. 产 生原因:我们知道Android的每一个Activ ...

  2. Android Weekly Notes Issue #236

    Android Weekly Issue #236 December 18th, 2016 Android Weekly Issue #236 本期内容包括: Google的物联网平台Android ...

  3. 让低版本的 Android 项目显示出 Material 风格的点击效果

    每天都被不同的需求纠缠的生活是幸福而又不幸的,这不我们家亲爱的设计师们又让我们在低版本的 Android 平台上实现一下类似于 Material Design 的点击效果. 虽然大家都知道 Mater ...

  4. Android Lint Checks

    Android Lint Checks Here are the current list of checks that lint performs as of Android Studio 2.3 ...

  5. [Android] 升级了新的android studio之后 发生如下的报错,The following classes could not be instantiated:

    The following classes could not be instantiated:- android.support.v4.widget.DrawerLayout (Open Class ...

  6. android常见问题(一)

    一:文本的颜色选择器: 在res目录下面创建color文件夹,在color文件夹下面创建font_style_colors.xml文件<?xml version="1.0" ...

  7. android 5.0 水波纹 实现

    1. 定义一个普通圆角背景的xml; rounded_corners.xml <?xml version="1.0" encoding="utf-8"?& ...

  8. Android 开源项目PhotoView源码分析

    https://github.com/chrisbanes/PhotoView/tree/master/library 这个就是项目地址,相信很多人都用过,我依然不去讲怎么使用.只讲他的原理和具体实现 ...

  9. Android ViewFlow的一个例子

    完成这个例子的步骤: 1.下载ViewFlow的源码,然后将类ViewFlow放在自己的工程的src的某个包下. 2.下载的源码里有2个工程view flow,viewflow-example.将vi ...

随机推荐

  1. Xtreme8.0 - Kabloom dp

    Xtreme8.0 - Kabloom 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/kablo ...

  2. xcode 拷贝新的ios image 进去以后 出现 the divices is locked

    苹果公司时不时的给你更新下ios系统.对于开发者来说.更新xcode是灾难性的. 一直在用xcode7.3.1,可是最新不小心把手机升级到 ios 10.1.1,这下好了,真机调试不行了.提示没有镜像 ...

  3. 有强大的cURL,忘掉httpclient的吧!

    这段时间想做一个网页采集的程序,由于一网站采用了防采集的办法,我的httpclient总是在登录后无法获取到我想要过去的链接.在无数次的跟踪过后发现原来人家给返回的是javascript拼成的页面,而 ...

  4. 将Azure WebSite(应用)集成到虚拟网络

    用过Azure的同学都知道如何将虚拟机加入虚拟网络,也非常简单,但是对于将应用(WebSite)集成到虚拟网络中却很少听到.今天我要讲的就是如何直接将我们部署在WebSite中的应用加入到虚拟网络. ...

  5. Ubuntu · Docker —— 从入门到实践

      https://yeasy.gitbooks.io/docker_practice/appendix/repo/ubuntu.html#1604-%E7%89%88%E6%9C%AC

  6. 巧用CSS3 :target 伪类制作Dropdown下拉菜单(无JS)

    :target 是CSS3 中新增的一个伪类,用以匹配当前页面的URI中某个标志符的目标元素(比如说当前页面URL下添加#comment就会定位到id=“comment”的位置,俗称锚).CSS3 为 ...

  7. C - 项目收藏

    Web框架 [荐]Kore:开源 C 语言 Web 框架 Raphters:A web framework for C ulfius:Web Framework for REST API in C, ...

  8. Unity3D脚本(MonoBehaviour)生命周期

    场景中有2个物体:A,B 每一个物体上绑定2个脚本:A,B 初始化log: Object : A , Script : B , Message : Awake Object : A , Script ...

  9. 多人开发时Git下冲突的产生和解决

    冲突的产生 很多命令都可能出现冲突,但从根本上来讲,都是merge 和 patch(应用补丁)时产生冲突. 而rebase就是重新设置基准,然后应用补丁的过程,所以也会冲突. git pull会自动m ...

  10. Make the DbContext Ambient with UnitOfWorkScope(now named DbContextScope by mehdime)

    The Entity Framework DbContext (or LINQ-to-SQL DataContext) is a Unit Of Work implementation. That m ...