boredream / boreplugin Goto Github PK
View Code? Open in Web Editor NEW[DEPRECATED] Android Studio 自动生成布局代码插件
[DEPRECATED] Android Studio 自动生成布局代码插件
如果要在布局中还要声明,我会直接写android:onclick。最主要勾选要比写代码要快的多
选中layout布局,快捷键alt+Insert,然后选择LayoutCreator或者选中布局后在菜单栏中的Code中选择LayoutCreator
按照上述这些方式无法找到啊
2020.3.1
应该是onItemClickListener比较合理
EditText用m驼峰命名方法生成的代码:
private EditText mEdit;
mEdit = (EditText) findViewById(R.id.edit);
private void submit() {
// validate
String editString = edit.getText().toString().trim();
if (TextUtils.isEmpty(editString)) {
Toast.makeText(this, "editString不能为空", Toast.LENGTH_SHORT).show();
return;
}
}
加粗的地方变量名不是mEdit, 导致找不到.
public class MapOptionView extends LinearLayout implements View.OnClickListener {
public MapOptionView(Context context, AttributeSet attrs) {
super(context, attrs);
onCreate();
}
private void onCreate() {
LayoutInflater.from(getContext()).inflate(R.layout.fmd_map_option, this);
}
@Override
public void onClick(View v) {
}
}
如上代码,选布局文件,只生成了属性字段,对应的findById代码没有生成
有人遇到这个问题了吗?
能否选择任意的 layout的 xml 都可以在当前类中生成 相应的 Find 方法
更新as之前是可以使用的,今天更新了一下as到3.4就不能使用了,Code下LayoutCreator是灰色不可用状态,请问是什么原因
建议加入这个功能
首先非常感谢你开发这个炫酷的插件,其次这种直接生成代码而不是注解的方式和我的想法不谋而合,我很赞同,不过我技术暂时还不够,做不了这个.
实际开发中会对Activity或Fragment进行抽取,初始化view往往不在Activity中进行操作,而在ViewHolder或者其它什么地方,用View.inflate()的方式充出一个view,这样子就没法用这个插件的功能了.
如果没有oncreat方法,能否直接在类中生成initView()方法,最好能指定view.findViewById(),当然前面的view名能自定义就好了.
示例如下:
public class CategoryInfoHolder extends BaseHolder<Object> {
private ImageView ivImage1, ivImage2, ivImage3;
private TextView tvName1, tvName2, tvName3;
@Override
public View initHolderView() {
View view = View.inflate(GooglePlayApplication.context, R.layout.adapter_category_info, null);
ivImage1 = (ImageView) view.findViewById(R.id.iv_image1);
ivImage2 = (ImageView) view.findViewById(R.id.iv_image2);
ivImage3 = (ImageView) view.findViewById(R.id.iv_image3);
tvName1 = (TextView) view.findViewById(R.id.tv_name1);
tvName2 = (TextView) view.findViewById(R.id.tv_name2);
tvName3 = (TextView) view.findViewById(R.id.tv_name3);
return view;
}
其实我觉得太麻烦的话,直接将代码直接生成在类中即可,具体手动移动下就行
回头研究下你的插件功能,可以一起着重开发下,哈
经过测试只能在activity自动生成 fragment中并不生效,支持一下fragment吧大神
感谢作者的插件, 提一个小小的建议.
变量命名方式一般都比较固定, 比如m驼峰, 但是每次都要去选一下, 如果能记住我的上次的选择就好了.
或者提供一个默认命名方式设置项.
这是我引入项目的报错,我使用的是win7的64位使用jdk1.7。cannot create class "action.LayoutCreatorAction" [Plugin: com.boredream.plugin.layoutcreator]
com.intellij.diagnostic.PluginException: cannot create class "action.LayoutCreatorAction" [Plugin: com.boredream.plugin.layoutcreator]
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convertStub(ActionManagerImpl.java:177)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convert(ActionManagerImpl.java:515)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.getActionImpl(ActionManagerImpl.java:495)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.getAction(ActionManagerImpl.java:488)
at com.intellij.openapi.actionSystem.DefaultActionGroup.unStub(DefaultActionGroup.java:354)
at com.intellij.openapi.actionSystem.DefaultActionGroup.getChildren(DefaultActionGroup.java:312)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl$5.compute(ActionManagerImpl.java:1315)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl$5.compute(ActionManagerImpl.java:1308)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:967)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1308)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1302)
at com.intellij.codeInsight.generation.actions.GenerateAction.preload(GenerateAction.java:99)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1320)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1323)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1302)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.doPreloadActions(ActionManagerImpl.java:1290)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.access$200(ActionManagerImpl.java:77)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl$4.run(ActionManagerImpl.java:1278)
at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:366)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:55)
Caused by: com.intellij.diagnostic.PluginException: action/LayoutCreatorAction : Unsupported major.minor version 52.0 [Plugin: com.boredream.plugin.layoutcreator]
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:130)
at com.intellij.ide.plugins.cl.PluginClassLoader.tryLoadingClass(PluginClassLoader.java:77)
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:66)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convertStub(ActionManagerImpl.java:153)
... 24 more
Caused by: java.lang.UnsupportedClassVersionError: action/LayoutCreatorAction : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.lang.ClassLoader.defineClass(ClassLoader.java:643)
at com.intellij.util.lang.UrlClassLoader._defineClass(UrlClassLoader.java:260)
at com.intellij.util.lang.UrlClassLoader.defineClass(UrlClassLoader.java:256)
at com.intellij.util.lang.UrlClassLoader._findClass(UrlClassLoader.java:225)
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:124)
... 30 more
看效果和ButterKnife差不多啊
早期的项目很多是 Butter Knife 生成的 能不能在控件变量命名上兼容 Butter Knife,这们改起来比较方便
好像不能传图啊
比如我的id是這样的 activity_anti_virus_scanned
我在生成对话框中 删除一部分变成這样
scanned
但是生成的变量还是: private LinearLayout activity_anti_virus_scanned;
因为RecyclerView的ViewHolder是要继承RecyclerView.ViewHolder的,能不能提供一个勾选,用于产生RecyclerView的ViewHolder。
没有自动生成setOnClickListener(this);和onClick方法
插件版本1.4,Android Studio 版本2.2.2
控件为一个TextView和一个RelativeLayout
Plugin Error:
LayoutCreator threw an uncaught NullPointerException..
具体布局内容应该是没有问题的,不知道哪产生的NullPointer
抱着个错误 “threw an uncaught PluginException. Disable Plugin”求指导
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.