Android studio format code won't auto break line

前端 未结 8 1404
名媛妹妹
名媛妹妹 2020-12-30 19:41
tempCanvas.drawArc(cx - mInnerCircleRadius, cy + mInnerCircleRadius,cy + mInnerCircleRadius,cy + mInnerCircleRadius);

For example, the above code i

相关标签:
8条回答
  • 2020-12-30 20:13
    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)

    0 讨论(0)
  • 2020-12-30 20:13

    As a reminder to others visiting this question, you can also manually add line breaks by hitting enter after the commas or other appropriate places in the code. Android Studio will automatically indent it. This makes long lines more readable.

    tempCanvas.drawArc(
            cx - mInnerCircleRadius, // You can also add comments 
            cy + mInnerCircleRadius, // to different parts of a line
            cy + mInnerCircleRadius, // this way.
            cy + mInnerCircleRadius);
    
    0 讨论(0)
  • 2020-12-30 20:14

    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

    0 讨论(0)
  • 2020-12-30 20:16

    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.

    0 讨论(0)
  • 2020-12-30 20:31

    If you don't wanna wrap a line:

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

    0 讨论(0)
  • 2020-12-30 20:34

    You can make it automatically for all files by

    Editor -> General -> Soft-Wraps, check the Soft-wrap files and input needed filetype (for example *.java) in input field, now any new and even opened files will autowrap long strings. No any additional actions needed.

    0 讨论(0)
提交回复
热议问题