Android studio format code won't auto break li

2020-02-26 02:51发布

tempCanvas.drawArc(cx - mInnerCircleRadius, cy + mInnerCircleRadius,cy + mInnerCircleRadius,cy + mInnerCircleRadius);

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?

7条回答
Root(大扎)
2楼-- · 2020-02-26 03:35
File> Settings > Editor > Code Style > Kotlin > 'Set from...' - 'Predefined Style' - 'Kotlin style guide' 

when you want to use predefined code style for Kotlin in Android Studio/Idea (general rules from Coding Conventions)

查看更多
唯我独甜
3楼-- · 2020-02-26 03:35

If you don't wanna wrap a line:

File -> Settings -> Editor -> Soft Wraps -> Uncheck Use soft wraps in editor

查看更多
The star\"
4楼-- · 2020-02-26 03:42

File -> Settings > Editor > Code Style.

Then select Wrap on typing CHECKBOX.

查看更多
甜甜的少女心
5楼-- · 2020-02-26 03:43
Configure > Settings > Editor > 'Use soft wraps in editor'

Or right click on the divider where you can choose to show line numbers, and click 'Use soft wraps'

This won't break your code at your commas, but it will wrap your code so it's not too long to read.

查看更多
手持菜刀,她持情操
6楼-- · 2020-02-26 03:48

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.

You do that on File -> Settings on Windows, or in Preferences on Mac OS.

To do this in Android Studio go to

File > Settings > Editor > Code Style

and set Right margin (columns) to 120 (or the line width you want)

Now go to

File > Settings > Editor > Code Style > Java > Wrapping and Braces (tab)

and check the checkbox Ensure right margin in not exceeded

Apply the changes and press OK

Now in the editor, to format your code to that line width, press:

Code > Reformat Code... 

Done

In Mac OS instead of File > Settings go to Preferences, follow the same steps.

查看更多
家丑人穷心不美
7楼-- · 2020-02-26 03:51

On the latest Android Studio:

  1. Goto File > Settings > Editor > Code style > Java > Wrapping and Braces
  2. Change do not wrap to wrap if long for all the items
  3. Now Select the portion of the text you want to format and press ctrl + Alt + L

enter image description here

查看更多
登录 后发表回答