重写GrideView中的onMeasure方法
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
然后再布局中使用重写后的GrideView
<com.probie.video.view.MyGridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/newest_grid"
android:numColumns="3"
android:verticalSpacing="15dp"
android:horizontalSpacing="15dp"
android:clipToPadding="true"
android:padding="15dp"
/>
使用重写后的GrideView设置属性android:numColumns="3"在as中预览是无法显示的,但是属性依然有效 。