android布局文件的可视化面板不能显示解决
2014-12-19 17:11
316 查看
不显示原因:
在布局文件中加入了自定义控件,并在自定义控件的构造函数或者其他绘制相关地方使用系统依赖的代码,会导致可视化编辑器无法工作报错,一般会在下方提示:Use
View.isInEditMode() in your custom views to skip code when shown in Eclipse
解决方法:
在自定义控件的构造函数中赋值语句后加如下判断:if
(isInEditMode()) { return; }
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.
例子:
public class MyRelativeLayout extends RelativeLayout { private Handler mainHandler = null; //与主Activity通信的Handler对象 public MyRelativeLayout(Context context, AttributeSet attrs) { super(context, attrs, 0); mContext = context; if (isInEditMode()) { return; } mainHandler = ((MainActivity)mContext).getHandler(); } }
相关文章推荐
- android布局文件的可视化面板不能显示解决
- Android Studio Rendering Problems不能显示xxx.xml布局文件
- android编辑布局文件时非要降低api level或者更改主题才能显示布局预览 的根本解决办法
- 解决不能显示所有的文件和文件夹问题
- KDE挂载Windows分区不能正常显示中文文件的解决方法
- souce insight 中makefile 和.s文件不能高亮显示解决办法
- U盘中文件不能显示解决方
- 关于在extjs中使用column布局,不能显示textfield的标签(fieldLabel)解决方法
- 关于电脑不能显示隐藏文件的解决办法
- UltraEdit不能对Matlab的M文件进行语法高亮显示问题的解决
- 解决Windows不能显示隐藏文件的问题
- 开发Android平板电脑程序不能全屏显示问题的解决
- excel2007 打开模板文件时不能显示chart对象的解决办法
- 打开chm文件不能显示内容的解决办法
- 隐藏文件始终不能显示的完美解决方法
- 解决修改“文件夹选项”后仍不能显示隐藏文件一例
- 不能显示隐藏文件的解决办法
- 【转】不能显示隐藏文件解决方法
- 解决Outlook 2007中收发邮件HTML文件不能显示图片的方法
- 关于在extjs中使用column布局,不能显示textfield的标签(fieldLabel)解决方法