Android GridView 布局文件编写教程:R.id.gridview 示例
如何在 Android 中创建并编写包含 R.id.gridview 的 XML 布局文件?
这个 ID 的 XML 文件应该是一个 GridView 控件的布局文件,您可以在 res/layout 目录下创建一个名为 gridview.xml 的文件,并在该文件中添加 GridView 控件的相关属性和布局,例如:
<?xml version='1.0' encoding='utf-8'?>
<GridView xmlns:android='http://schemas.android.com/apk/res/android'
android:id='@+id/gridview'
android:layout_width='match_parent'
android:layout_height='match_parent'
android:numColumns='3'
android:verticalSpacing='10dp'
android:horizontalSpacing='10dp'
android:stretchMode='columnWidth'
android:gravity='center'
/>
在该布局文件中,我们设置了 GridView 的 ID 为 R.id.gridview,设置了 GridView 的宽度和高度为 match_parent,设置了每行显示 3 个 item,设置了 item 之间的垂直和水平间距,以及 item 宽度的自适应和内容居中显示。
原文地址: https://www.cveoy.top/t/topic/nGZM 著作权归作者所有。请勿转载和采集!