Layout Editor in Android Studio is used for building layouts. It enables you to build layouts by dragging UI elements into a visual design editor instead of writing layout XML. The design editor can preview layout on different Android devices and versions. You can position the elements in the layout, add constraints, and set attributes.
Layout Editor appears when you open an XML layout file.
Parts of Layout Editor
Below figure shows layout editor in Android Studio.
Various component as marked in the above image are
- Palette: It provides a list of components and layouts that you can drag into your layout in the editor.
- Component Tree: It shows the hierarchy of components in layout.
- Toolbar: It provides buttons to configure layout appearance in the editor and change layout attributes. You can preview the layout on different size of the display to check if constraints work as expected. It also has controls for find alignments and connection tools.
- Design editor: Edit your layout in Design view, Blueprint view, or both.
- Attributes: It shoes the controls for the selected view’s attributes. Attributes are properties for components in layout. It will describe visual aspects of components.
- View mode: Configure view of layout in either Code, Design or Split. Split mode shows both the Code and Design windows at the same time.
Create New layout
New layout using Android Studio’s main menu
- Click the module in project windows.
- Go to File > New > XML > Layout XML File, in the main menu.
- In the dialog that appears, set the file name and follow the instruction.
- Click Finish to create the layout.
To create new layout using Project view
- Choose the Project view from within the Project window.
- Right-click the layout directory where you’d like to add the layout.
- In the context menu that appears, click New > Layout Resource File.
To create new layout using Resource Manager
- In the Resource Manager, select the Layout tab.
- Click the + button, and then click Layout Resource File.