android 怎么让父布局和子布局一起滑动

2024-11-13 03:57:21
推荐回答(1个)
回答(1):

把你所有想一起动的控袜腊件放到一个scrollview下,然嫌好竖后listview用这个
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
int mExpandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, mExpandSpec);
}
}

scrollview‍用这个

/**
* 解决ScrollView嵌套ViewPager出现的滑芹大动冲突问题
*/
public class MyScrollView extends ScrollView {
View.OnTouchListener mGestureListener;
// 滑动距离及坐标
private float xDistance, yDistance, xLast, yLast;
public MyScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
xLast = ev.getX();
yLast = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();

xDistance += Math.abs(curX - xLast);
yDistance += Math.abs(curY - yLast);
xLast = curX;
yLast = curY;

if(xDistance > yDistance){
return false;
}
}
return super.onInterceptTouchEvent(ev);
}
}