解决ScrollView嵌套ListView冲突问题,并且添加阻尼效果

关于阻尼效果,之前的帖子已经有过详细介绍

主要说下ScrollView嵌套ListView冲突问题,由于Listview本身就是继承ScrollView而来的,所以在ScrollView里嵌套ScrollView肯定会发生冲突。

解决方案:重写ListView或者GridView的OnMesure 方法。

自定义ListView

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

public class MyListView extends ListView {

	public MyListView(Context context) {
		super(context);
	}

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

	public MyListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

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

		super.onMeasure(widthMeasureSpec, expandSpec);
	}

}

 调用方法:

listView = (MyListView) findViewById(R.id.listView);
BounceScrollView scrollView = (BounceScrollView) findViewById(R.id.scrollView);
scrollView.smoothScrollTo(0,0);


阻尼效果的BounceScrollView详见:http://www.cnblogs.com/yangcong/p/3525061.html

参考帖子:http://www.apkbus.com/forum.php?mod=viewthread&tid=123514

原文地址:https://www.cnblogs.com/yangcong/p/3557797.html