Android GridView is a ViewGroup
that displays items in a two-dimensional, scrollable grid. In this tutorial, we will build an image gallery using Android GridView.
Android GridView是一个ViewGroup
,用于在二维可滚动网格中显示项目。 在本教程中,我们将使用Android GridView构建图像库。
Android GridView (Android GridView)
Android GridView layout in one of the most useful layouts in android. GridView is mainly useful when we want show data in grid layout like displaying images or icons. This layout can be used to build applications like image viewer, audio or video players in order to show elements in grid manner.
Android GridView布局是android中最有用的布局之一。 当我们希望以网格布局显示数据(例如显示图像或图标)时,GridView主要有用。 此布局可用于构建诸如图像查看器,音频或视频播放器之类的应用程序,以便以网格方式显示元素。
GridView elements are not generally predefined and the data can be inserted into the layout using Adapters like ListAdapter etc. We can control the number of columns, their width, and relevant spacing.
GridView元素通常不是预定义的,可以使用ListAdapter等适配器将数据插入布局中。我们可以控制列数,列宽和相关间距。
Android GridView属性 (Android GridView Attributes)
- android:id : This is the ID which uniquely identifies the layout android:id :这是唯一标识布局的ID
- android:columnWidth : This specifies the fixed width for each column. This could be in px, dp, sp, in, or mm android:columnWidth :这指定每列的固定宽度。 可以是px,dp,sp,in或mm
- android:gravity : Specifies the gravity within each cell. Possible values are top, bottom, left, right, center, center_vertical, center_horizontal etc. android:gravity :指定每个单元格内的重力。 可能的值是上,下,左,右,中心,center_vertical,center_horizontal等。
- android:horizo