format code (shortcut key for eclipse format code block: Ctrl + Shift + F)
1. Format java code:
But will we encounter a time when pressing Ctrl + Shift + F doesn’t work
Ctrl + Shift + F is a simple and complex replacement in Sogou Pinyin. Once you install Sogou Pinyin, this shortcut key will be occupied, but you can set the simple and complex shortcut keys of Sogou for other users. In other cases, you can use the format shortcut in eclipse
3. The shortcut key of Ctrl + Shift + F is occupied by other software (such as Sogou Pinyin and Baidu Pinyin)
② Eclipse automatically formats code when saving filesmany people don’t know that eclipse has a very useful function, that is, the function of automatically formatting source code. In general, people use Ctrl + Shift + F to format files manually, which is a waste of time.
In fact, eclipse already has an automatic formatting function. By default, this function is not available.
Specific method: Windows — > Preferences–> Java –> Editor–> Save actions. You can see the options on the right. Check “perform the selected actions on save”. You can select or configure other options according to your needs.
Don’t forget, finally, apply and OK.
2. Format XML code: Ctrl + Shift + F, but you need to make the following modificationsbut for XML files, sometimes after formatting, the configuration attributes of a control are all packed in one line, which is very inconvenient to read and modify.
We hope that the best formatting effect is as follows: each property configuration of the control occupies one line, which is easy to read and modify, and the control without child elements can be used directly/> close:
<?xml version=”1.0″ encoding=”utf-8″?>
< LinearLayout xmlns:android= ” http://schemas.android.com/apk/res/android ”
android:layout_ width=”fill_ parent”
android:layout_ height=”fill_ parent”/>
android:text= “Some Content”
android:layout_ width=”wrap_ content”
android:layout_ height=”wrap_ content” />
In order to achieve the above formatting effect, you need to modify some configuration of eclipse and do some additional operations
modify the XML format configuration of eclipse
The configuration of this step is to make the formatting effect occupy one line for each property configuration of the control. Enter window/preferences and expand to XML/XML files/editor,
Check “split multiple attributes each on a new line”, as shown in the figure below:
< TextView android:id= “@+id/TextView01”
- [Solved] Java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
- Android Your content must have a ListView whose…
- Ffmpeg scaling — the solution of “width / height not divisible by 2”
- [Solved] android.view.InflateException: Binary XML file line #0: Error inflating class ImageView
- Elimination of warning message “nested weights are bad for performance”
- Sublime run code – open in browser shortcut key settings
- UICollectionView must be initialized with a non-nil layout parameter [Solved]
- Android: layout layout page can not be displayed, prompt: one or more layouts are missing the layout_width or layout_height attrib…
- How to Solve Issue: ScrollView can host only one direct child
- Formatter-maven-plugin formatter validate Error