你可以在 Android / eclipse 中使用 #regions
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9866245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can you have #regions in Android / eclipse
提问by John
in .net you have Regions that you can collapse and remove lots of code down to one line. is there something like this in Android / Java / Eclipse.
在 .net 中,您有可以折叠和删除大量代码到一行的区域。Android / Java / Eclipse 中是否有类似的东西。
#Region "Initialize"
private void DisplayHome(){
Intent i = new Intent(this, SMSInternetActivity.class);
finish();
startActivity(i);
}
private void DisplaySettings(){
Intent i = new Intent(this, DisplaySettings.class);
finish();
startActivity(i);
}
This just being an example.. #End Region
这只是一个例子.. #End Region
采纳答案by louielouie
There's a plug-in for that! It is called Coffee-Bytes. It is not in active development, but there are some programmers out there that are keeping the functionality going by updating it for new Eclipse releases.
有一个插件!它被称为咖啡字节。它没有处于积极的开发阶段,但有一些程序员通过为新的 Eclipse 版本更新它来保持功能的正常运行。
There's two places where you can get the most latest install for Eclipse 3.7 (Indigo):
有两个地方可以获得 Eclipse 3.7 (Indigo) 的最新安装:
http://code.google.com/p/academic-cloud/downloads/detail?name=eclipse-folding-plugin.tar.gz&can=2&q=
http://kosiara87.blogspot.com/2011/12/how-to-install-coffee-bytes-plugin-in.html
http://code.google.com/p/academic-cloud/downloads/detail?name=eclipse-folding-plugin.tar.gz&can=2&q=
http://kosiara87.blogspot.com/2011/12/how-to-install-coffee-bytes-plugin-in.html
Basically, you download the archive, then unpack it. Then you copy the feature from the features folder into your Eclipse installation in the Eclipse features folder. Do the same thing with the JAR found in the plugins folder, it goes into your Eclipse plugins folder. Then restart Eclipse.
基本上,您下载存档,然后解压缩它。然后将特性文件夹中的特性复制到 Eclipse 特性文件夹中的 Eclipse 安装中。对 plugins 文件夹中的 JAR 执行相同的操作,它会进入您的 Eclipse plugins 文件夹。然后重新启动 Eclipse。
There's a good SO answer that shows how to set it up:
有一个很好的 SO 答案显示了如何设置它:
How to use Coffee-Bytes code folding
Note that you may have to restart Eclipse for this new style of code folding to start working. Enjoy!
请注意,您可能必须重新启动 Eclipse 才能使这种新的代码折叠样式开始工作。享受!
回答by Sir Duende
Using Android Studio:
使用安卓工作室:
//region "Initialize"
private void DisplayHome(){
Intent i = new Intent(this, SMSInternetActivity.class);
finish();
startActivity(i);
}
private void DisplaySettings(){
Intent i = new Intent(this, DisplaySettings.class);
finish();
startActivity(i);
}
//endregion
回答by AkaZn
I believe this is a feature of the IDE i.e. Visual Studio, not .NET in general. You, in theory, can write a plugin for Eclipse that can collapse region in Java code. Eclipse already have the ability to collapse imports and functions.
我相信这是 IDE 的一个特性,即 Visual Studio,而不是一般的 .NET。理论上,您可以为 Eclipse 编写一个插件,该插件可以在 Java 代码中折叠区域。Eclipse 已经能够折叠导入和函数。
回答by noob
You can use Intellij's feature for code folding using //region
and //endregion
. Works great in Android Studio. However for Eclipse, you'll need a plugin to do that.
您可以使用 Intellij 的功能来使用//region
和进行代码折叠//endregion
。在 Android Studio 中运行良好。但是对于 Eclipse,您需要一个插件来做到这一点。
Source: Taken from Answer of Alexander Bezrodniy
资料来源:摘自Alexander Bezrodniy 的回答
回答by android developer
You need to perform the "surround with" operation (default key combination is CTRL+ALT+T), which allows you to use one of 2 ways to specify code as a region:
您需要执行“环绕”操作(默认组合键为 CTRL+ALT+T),这允许您使用以下两种方式之一将代码指定为区域:
editor-fold:
//<editor-fold desc="Description"> code //</editor-fold>
region & endregion :
//region Description code //endregion
编辑折叠:
//<editor-fold desc="Description"> code //</editor-fold>
区域和末端区域:
//region Description code //endregion
As I remember, you must choose one of them to be used for the whole project. Maybe I'm wrong and it's only for a single file (and maybe there isn't a restriction at all).
我记得,您必须选择其中之一用于整个项目。也许我错了,它仅适用于单个文件(也许根本没有限制)。
回答by Basheer AL-MOMANI
yes, and the fastestway to do it in
Android Studio
是的,而且是最快的方法
Android Studio
highlight the code
you want to surround it- press
ctrl
+alt
+t
- press
c
==> then enter the description - enjoy
highlight the code
你想包围它- 按
ctrl
+alt
+t
- 按
c
==> 然后输入说明 - 请享用