listview嵌套gridview

1.首先要自定义一个继承gridview的类

public class MyGridView extends GridView {
    public boolean hasScrollBar = true;
    public MyGridView(Context context) {
        super(context);
    }

    public MyGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

2.在布局中引用这个自定义gridview

<com.example.administrator.tunrb.MyFragment.Single_fragment.MyGridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/single_gridview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnWidth="80dp"
    android:background="#ffffff"
    android:horizontalSpacing="5dp"
    android:numColumns="auto_fit"
    android:verticalSpacing="5dp"></com.example.administrator.tunrb.MyFragment.Single_fragment.MyGridView>
原文地址:https://www.cnblogs.com/anni-qianqian/p/5518904.html