问题
You know how in eclipse you can edit the XML file using the built-in eclipse GUI for adding GUI components? I'm looking to create my own component that I can add so I can drag and drop like the rest of the components. I've looked for a tutorial to no avail and couldn't find anything. Does anyone know how to do this?
Mind you I am using Java.
回答1:
You can create custom layout or component by creating a class that extends ViewGroup or the component (Ex: Button) that you want to create.
This will display your custom component under "Custom and Library Views" tab in graphical layout view of the xml.
回答2:
The newer versions of the android developer tools (ADT) supports custom views in the layout editor. I believe you need just make sure that your custom view has the constructor that takes attributes as an argument. Check out this video from Google IO 2011 which highlights some of the additions from the (what is now) 5 updates ago: http://www.youtube.com/watch?v=Oq05KqjXTvs
来源:https://stackoverflow.com/questions/8829959/customized-gui-components-for-android-in-eclipse