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>

 

相关文章:

  • 2021-12-05
  • 2021-12-11
  • 2022-12-23
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2021-07-01
猜你喜欢
  • 2021-12-05
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2021-04-26
  • 2021-07-31
  • 2022-12-23
相关资源
相似解决方案