Notes GridView (grid view) class:

GridView indirectly inherits the AdapterView class, so it can include multiple list items (AdapterView is an abstract base class, it inherits from the ViewGroup class, belongs to the container, can include multiple list items, and can be displayed in a suitable way, in the specified multiple lists Item, use the Adapter object provided)

Display multiple components in a row and column distribution, usually used to display pictures or icons, etc.

Commonly used XML attributes of GridView:

android:columnWidth is used to set the width of the column android:gravity is used to set the alignment
android:horizontalSpacing is used to set the horizontal spacing between the elements android:numColumns is
used to set the number of columns, the attribute value is usually a value greater than 1, if There is only 1 column, then it is best to use ListView to implement android:stretchMode
to set the stretching mode, where the attribute value can be none (no stretching), spacingWidth (only stretching the distance between single elements), columnWidth (only stretching The table element itself) or spacingWidthUniform (the table element itself, the spacing between the elements is stretched together)
android:verticalSpacing (used to set the vertical spacing between each element)

When using the GridView component, the Adapter class is usually used to provide data for the GridView component. The
Adapter class is an interface that represents the adapter object. It is the bridge between the component and the data. It can process data and bind it to the corresponding component. Commonly used implementation classes include:

ArrayAdapter Array adapter, usually used to package multiple values ​​of the array into multiple list items, can only display one line of text SmipleAdapter
simple adapter, usually used to package multiple values ​​of the List collection into multiple list items, you can customize each This kind of effect, powerful function
SmipleCursorAdapter is similar to SmipleAdapter, except that it needs to correspond the field of Cursor (the cursor object of the database) to the component ID, so as to display the contents of the database in the form of a list.
BaseAdapter is an abstract class, inheriting it needs to be implemented More methods, usually it can customize each list item to the maximum, and it also has high flexibility

Guess you like

Origin blog.csdn.net/qq_42823109/article/details/93451318