Usage example of GridView in Android

In Android programming, GridView and listview are commonly used multi control layouts, and GridView is the first choice to realize the nine house diagram! This article is to introduce how to use GridView to realize Jiugong diagram. There are many uses of GridView. The most widely introduced method on the Internet is to implement an imageadapter, inherit baseadapter, and then use it for GridView. Similar methods will not be repeated in this paper. The GridView usage introduced in this paper is very similar to the listview introduced before.

Let's take a look at the results of the code running in this article:

Three files need to be added / modified in this article: main.xml and night_ Item.xml, java source code.

The source code of main.xml is as follows. It is a girdview for loading items:

Here are some properties:

Android: numcolumns = "auto_fit", the number of columns in the GridView is set to automatic. Android: columnwidth = "90dp", the width of each column, that is, the width of the item. Android: stretchmode = "columnwidth", scaling is synchronized with the size of the column width. Android: verticalspating = "10dp", the margin between two rows, for example, the spacing between row 1 (No.0 ~ No.2) and row 2 (No.3 ~ No.5) is 10dp. Android: horizontalspacing = "10dp", The margin between two columns.

Next, let's introduce night_ Item.xml, which is similar to imageitem.xml of listview:

Finally, there is the Java source code, which is very similar to the Java source code of the listview above, but there is more "selected" event processing:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>