自定义的view无法在layou视图中查看,可尝试如下编辑:及在构造函数中判断
isInEditMode的状态,返回false才进行初始化
public class GraphView extends View
{
public GraphView(Context context, AttributeSet attrs) {
super(context, attrs);
if(!isInEditMode())
init(context);
}
public GraphView(Context context) {
super(context);
if(!isInEditMode()){
init(context);
}
}
参考地址:http://stackoverflow.com/questions/15423149/how-to-use-isineditmode-to-see-layout-with-custom-view-in-the-editor
时间: 2024-10-17 13:21:32