android GridView在ScrollView中显示不全问题解决

重写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中预览是无法显示的,但是属性依然有效 。

发布了12 篇原创文章 · 获赞 22 · 访问量 4149

猜你喜欢

转载自blog.csdn.net/qq_41173427/article/details/104360092