scrollview 套gridview的问题

1、gridview 高度的问题

重写gridview

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

此也适用于listview
问题:
在使用中gridveiw的适配器 中有TextView,此文本的有多行的话,还会出现问题,
那就是在测量的时候GridView只会测量第1个childView,至使若第1个childView只有一行,而其他有多行,后面就会看不见了,
解决方案:将文本的行数设为固定

<TextView
        android:id="@+id/gridtext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:gravity="center_horizontal"
        android:lines="2"
        android:maxLines="2"
        android:text="fdsaf"
        android:textColor="@android:color/black"
        android:textSize="@dimen/Font_Size_16" />

2、进入时 scrollview不是在顶部

重写ScrollView

@Override
  protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
      //禁止scrollView内布局变化后自动滚动
      return 0;
  }

参考

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容