Custom Android Views in Eclipse Visual Editor

前端 未结 3 1086
萌比男神i
萌比男神i 2020-12-09 12:22

In my applications, I often rely on custom build views, such as in the following example.




        
3条回答
  •  爱一瞬间的悲伤
    2020-12-09 12:46

    You can do this in your Custom View:

    if(!isInEditMode()){
       // Your custom code that is not letting the Visual Editor draw properly
       // i.e. thread spawning or other things in the constructor
    }
    

    http://developer.android.com/reference/android/view/View.html#isInEditMode()

    This allows you to hide code from the ADT Plugin XML Viewer and hopefully display you a layout!

    View.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.

提交回复
热议问题