In this android tutorial you will learn about android simple and custom gridview example.
在本android教程中,您将学习有关android简单和自定义gridview示例的信息。
In Android, GridView is a ViewGroup that is used to display items in a two dimensional scrollable grid form. You might have seen image gallery in Android mobiles, it is created using GridView layout.
在Android中,GridView是一个ViewGroup,用于以二维可滚动网格形式显示项目。 您可能已经在Android手机中看到了图片库,它是使用GridView布局创建的。
Here we will see two examples, one is simple GridView layout with some text and another is custom GridView layout with image and text.
在这里,我们将看到两个示例,一个是带有某些文本的简单GridView布局,另一个是带有图像和文本的自定义GridView布局。
Android GridView示例 (Android GridView Example)
Android Simple GridView示例 (Android Simple GridView Example)
Make an android project with package name com.gridviewexample and add following code in respective files.
使用包名称com.gridviewexample创建一个android项目,并在相应文件中添加以下代码。
activity_main.xml
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/simpleGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="100dp"
android:numColumns="aut