AndroidStudio basic linear layout

Table of contents

Inheritance Diagram

 common attributes

1. Create an Android application

3. String resource file

Start the application to see the effect

5. Set the layout properties and view the effect

(4) Set the linear layout background

1. Create an Android application

2. Prepare picture material

3. Main layout resource file


Linear layout (LinearLayout) is a relatively common and simple layout method. In this layout, all child elements are arranged on the interface in vertical or horizontal order. If it is arranged vertically, each child element occupies a row, if it is arranged horizontally, each child element occupies a column. Linear layout can support layout style nesting to implement complex layout styles.

Inheritance Diagram

LinearLayout is a subclass of ViewGroup

 common attributes

Attributes meaning
layout_height Height, unit: dp (wrap_content, match_parent)
layout_weight Width, unit: dp (wrap_content, match_parent)
orientation direction (vertical, horizontal)
gravity Alignment (left, right, center, top, bottom…)
background Background (color [color], picture [drawable], selector [selector])
weight Specific gravity (used to carve up mobile phone screens)
padding padding(paddingLeft, paddingRight, paddingTop, paddingBottom)
margin Margins (marginLeft, marginRight, marginTop, marginBottom)

1. Create an Android application

  Create an Android application based on Empty Activitya template - LinearLayoutDemo

 Click the [Finish] button

2. Main layout resource file

Change the constraint layout to a linear layout and delete the default label

 add two buttons

3. String resource file

Open the string resource file strings.xml to modify the theme

Start the application to see the effect

Found two buttons placed horizontally, in the upper left corner of the window

5. Set the layout properties and view the effect

(1) Set the linear layout direction orientationproperty

(2) Set the inner margin of the linear layoutpadding (paddingTop, paddingBottom, paddingLeft, paddingRight)

(3) Set the linear layout alignment gravity (left, center, right, top, bottom can be combined to form a variety of alignments) set the upper right alignment - right|top

 Delete the right margin of [Button 1]

 Set center alignment - center

 Set Bottom Left Alignment - left|bottom

 Set top center alignment - center

(4) Set the linear layout background

Set background color (takes color variable)

Set the background color (takes a color constant)

 set background image

Set the background selector

Add a linear layout, set a custom border

 

 Realize border gradient effect

nested linear layout

1. Create an Android application

Empty ActivityCreate android app  based on -NestedLinearLayout

2. Prepare picture material

Copy a few small pictures to the res/drawable directory

3. Main layout resource file

Main layout resource file - activity_main.xml

Change the constraint layout to a linear layout, add three linear layouts, and divide the mobile phone screen vertically according to the ratio of 1:2:3

Modify the layout and see the effect

Add three image views arranged horizontally to the first layout

 

 Add a horizontal linear layout to the second layout, add four buttons inside

 Add an edit box to the second layout

 Add three layouts and add buttons to the third layout

 operation result

Guess you like

Origin blog.csdn.net/hollow_future/article/details/127396809