ScrollView和GridView滚动冲突的解决

GridView需要使用自定义的,定义一个MyGridView

public class MyGridView extends GridView {
}

重写onMeasure方法

        @Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

		int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
				MeasureSpec.AT_MOST);

		super.onMeasure(widthMeasureSpec, expandSpec); 
	}

布局中使用自定义的 GridView 

   <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
 

            <com.sportstar.widget.MyGridView
                android:id="@+id/gridView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:horizontalSpacing="4dp"
                android:numColumns="3"
                android:stretchMode="columnWidth"
                android:verticalSpacing="4dp" >
            </com.sportstar.widget.MyGridView>
 
        </LinearLayout>
    </ScrollView>

在代码中设置ScrollView的属性
scrollView = (ScrollView) findViewById(R.id.scrollView1);
scrollView.smoothScrollTo(0,0);

设置一下GridView禁止滚动

       gridView.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                 return MotionEvent.ACTION_MOVE == event.getAction() ? true
                           : false;
            }
       });

-------------------------------------------------------------------------------------------------------------割割更健康-----------------------------------------------------------------------------------------------------------

好了 打完收工,看看效果图:



可以看到,GridView已经全部展开

有什么疑问,欢迎留言,评论,私信,求不喷~~微笑微笑大笑大笑





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值