Android studio 格式代码不会自动断行 [英] Android studio format code won't auto break line
问题描述
tempCanvas.drawArc(cx - mInnerCircleRadius, cy + mInnerCircleRadius,cy + mInnerCircleRadius,cy + mInnerCircleRadius);
比如上面的代码太长,所以我想在每个,
处换行.Eclipse 会这样做,但当我点击 format code
时,Android Studio 不会断线.有什么方法可以做到吗?
For example, the above code is too long, so I want to break the line at every ,
. Eclipse will do it but Android Studio won't break the line when I hit format code
. Is there any method to do it?
推荐答案
在 Android Studio(可能还有任何其他 IDE)中,您不会用 、
或任何其他字符换行(换行),定义最大线宽并设置格式化程序以确保不超过最大线宽.
In Android Studio (and probably any other IDE) you don't break (wrap) lines by ,
or any other character, you define a maximum line width and set the formatter to ensure the maximum line width is not exceeded.
你在 File ->Windows 上的设置
,或 Mac OS 上的 Preferences
.
You do that on File -> Settings
on Windows, or in Preferences
on Mac OS.
要在 Android Studio 中执行此操作,请转到
To do this in Android Studio go to
File > Settings > Editor > Code Style
并将右边距(列)
设置为120
(或您想要的线宽)
and set Right margin (columns)
to 120
(or the line width you want)
现在去
File > Settings > Editor > Code Style > Java > Wrapping and Braces (tab)
和check
复选框确保右边距不超过
应用更改并按确定
现在在编辑器中,要将代码格式化为该行宽,请按:
Now in the editor, to format your code to that line width, press:
Code > Reformat Code...
完成
在 Mac OS 中而不是 File >设置
进入Preferences
,按照同样的步骤操作.
In Mac OS instead of File > Settings
go to Preferences
, follow the same steps.
这篇关于Android studio 格式代码不会自动断行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!