GrideView 经常被用到,这里做一个用选择图片的功能。
废话不多说,上图:
1. GrideView 在activity或者fragment中的布局布局
<GridView
android:id="@+id/gvPhotos"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:columnWidth="90dp"
android:horizontalSpacing="8dp"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="8dp" />```
2. GrideView 的item的布局
这里有个控件叫做 GrideViewItemLayout ,是专门为GrideView做的,用于item显示为正方形的。源码在最后
<?xml version="1.0" encoding="utf-8"?>
<com.mg.axe.puzzlegame.GrideViewItemLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/ivPic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
<RelativeLayout
android:id="@+id/rlSelected"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background=