---
title: "android 自定义组件 在 graphical layout 不显示的问题"
author: "squall140"
date: "2012-12-15T20:06:11Z"
tags: []
categories: ["企业架构"]
slug: "android-graphical-layout"
draft: false
lastmod: "2012-12-15T20:06:11Z"
id: 1748475
url: "https://squall140.iteye.com/blog/1748475"
---

经过各种分析，结果发现这样可以解决：

在你的自定义控件的**构造函数，onLayout()，onFinishInflate()的super方法**后面加上如下代码，即可在Graphical Layout界面下看到，但是不会显示控件的内容，不过你可以只在你报错的地方加上这个代码：

```
if (isInEditMode()) {
    return;
}
```

 

其实你查看error log 就会发现log里告诉了你错误在哪一行， 按照提示将这一行加入到if（isIntouchMode（））｛｝中，就行了。是因为有些数据或者类无法在onFinishInflate()（即解析xml布局时）方法里调用到