Custom Android Views in Eclipse Visual Editor

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

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
android:layout_width="fill_parent" >





  • jquery signalr client works- but in java it cannot be made to work
  • Notification Sound, Vibration and LED don't work
  • Unicode support for android
  • android/iphone click to call in html
  • How to Search in Google Map Api V2 Android?
  • How can you put the android emulator into sleep mode?
  • The problem is, I don’t know how if it will be displayed correctly until I run it on a real device or on the emulator. Moreover, if I found something wrong I would have to perform changes on it and deploy the app again to see if the changes worked as you expected.

    This can be a long and boring process, especially if the application requires some interaction to get to the activity you want to check.

    Using the visual editor doesn’t work as it cannot load the custom view.

    Is there another way to check how views are displayed without running across the whole application?

    Related posts:

    Android: Background Image Size (in Pixel) which Support All Devices
    State list drawable and disabled state
    How to send key event to an edit text
    change checkbox background color in android
    Mute a playing video by VideoView in Android Application
    How to set height of one layout component to the same height of another component?
  • Youtube data API : Get access to media stream and play (JAVA)
  • How do I toggle a progress dialog between determinate and indeterminate?
  • ImageView not keeping max height and width
  • Scrollbar not showing in RecyclerView
  • Android Fragments should I reuse 1 fragment or create new instances?
  • How to change Options menu dots color?
  • 3 Solutions collect form web for “Custom Android Views in Eclipse Visual Editor”

    You can do this in your Custom View:

       // Your custom code that is not letting the Visual Editor draw properly
       // i.e. thread spawning or other things in the constructor

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


    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.

    You could create a skeleton activity that loads just the view you want to see and populate it with enough data to make it display.

    I’m using Android Studio so I’m not sure this answer will apply to your case.

    I think you could override onDraw method in the custom view, like this exemple keeping the aspect ratio of an inner image:

    protected void onDraw(Canvas canvas) {
        // TODO: consider storing these as member variables to reduce
        // allocations per draw cycle.
        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        int paddingRight = getPaddingRight();
        int paddingBottom = getPaddingBottom();
        int w = getWidth() - paddingLeft - paddingRight;
        int h = getHeight() - paddingTop - paddingBottom;
        w = w<h ? w : h;
        h = w;
        // Draw the example drawable on top of the text.
        if (dieDrawable != null) {
            dieDrawable.setBounds(paddingLeft, paddingTop,
            paddingLeft + w, paddingTop + h);

    This method runs both in the emulator and the designer.

    It runs as well for any event that redraws the view (onSizeChanged, onLayout, etc…)

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.