No preview of custom views on UI designer in Eclipse

梦想的初衷 提交于 2019-12-23 19:22:49

问题


Background

I've been creating many types of custom views, and normally i get their previews shown just fine on the UI designer of ADT.

lately, after updating to the newest version of the ADT ( 22.0.5.v201307292155--757759 ), i can't see any type of custom view, not even the simplest one .

The problem

now, i know for sure that custom views can be previewed fine , since if i create a new workspace and create them, i can see them just fine.

the problem is that on the current workspace, which has many settings for its projects, i keep getting this error:

The following classes could not be found: - ... (Change to ... , Fix Build Path, Edit XML, Create Class)

where "..." is the class of the custom view.

i also get a gray rectangle for each custom view i use, and Lint also complains:

Class referenced in the layout file, ..., was not found in the project or the libraries

this is very weird, since i used the correct syntax for the custom views in the XML (and i've done it a lot). even drag&drop didn't help.

it's also weird because eclipse can find the classes (using CTRL+click on the XML tag goes right to the correct class) , it just doesn't seem to find them while viewing.

i've also tried to uninstall ADT and reinstall it, but it didn't help. i've also tried to uninstall and re-install some relevant components from the SDK manager. nothing helped.

here's a sample code of a custom view that doesn't show well at all :

public class CustomTextView extends TextView {

    public CustomTextView(Context context) {
        super(context);
    }

    public CustomTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
}

as you can see, there is nothing special in this code.

The question

Why does it occur? how can i fix it? can i perhaps copy all (and i mean all) the settings of the current workspace to a new one to solve it?

Does anybody else have this problem? is it an ADT bug?

NOTE: I do not want to reset the workspace. it has far too many special settings for the projects within it.


回答1:


Did you also update the Eclipse plugin together with the ADT?

I know this happened to me once it was probably what i missed.

Maybe if there are updates to the actual platform SDK's update them as well. you can also try to change the version of the SDK the preview uses to the latest or earlier one (this is the android icon on the top left in the preview which should say 18).

I know that some custom views don't render if you use shadows for example on text. Then you just set the isInEditMode flag inside the custom view to skip those.

At the very end download a new zip with the ADT bundle and try again :)

Hope this helps somehow.




回答2:


Have you included the other workspace library into the new project? E.g. Project->Properties->Android->Library "Add" the old workspace project.



来源:https://stackoverflow.com/questions/18119907/no-preview-of-custom-views-on-ui-designer-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!