本来我们用recycview代替了listview之后就很少会遇到scrollview了但是产品需求总是在不断的更新。在时间与技术的探索之下,还是会有一部分兄弟会选择这样的布局,下面我就来说说使用之后遇到的一些坑的解决方案。
1 scrollview 签到listview 的解决方案
(1)
只需在MainActivity中 找到listview 和 scrollview
然后给listview设置监听事件 外部解决法
listView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == MotionEvent.ACTION_UP){
scrollView.requestDisallowInterceptTouchEvent(false);
}else{
scrollView.requestDisallowInterceptTouchEvent(true);
}
return false;
}
});
或者
listView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
listView.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
第二种方法
只需重写listview即可 ,内部解决发
package com.bawei.day06;import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListView;
public class ListViewForScrollView extends ListView {
int mLastMotionY;
boolean bottomFlag;
public ListViewForScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (bottomFlag) {
getParent().requestDisallowInterceptTouchEvent(true);
}
return super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
int y = (int) ev.getRawY();
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
mLastMotionY = y;
break;
case MotionEvent.ACTION_MOVE:
int deltaY = y - mLastMotionY;
if (deltaY < 0) {
View child = getChildAt(0);
if (chi