所以我在我的应用程序中使用了上滑面板库,并且我试图ScrollView
在滑动面板中实现一个。由于滑动面板和 ScrollView 都由垂直滚动控制,这给我带来了一些问题。
一旦面板一直向上滑动,并且当 ScrollView 滚动到顶部时,我通过切换面板的拖动视图来部分工作。
我现在面临的问题是,当将面板滚动到顶部时,滚动不会像在 Google 地图中那样转移到 ScrollView。有点难以解释,所以请看这里的视频: www.youtube.com/watch ?v=9MUsmQzusX8&feature=youtu.be
这是面板幻灯片监听器:
...
slidePanel.setEnableDragViewTouchEvents(true);
slidePanel.setPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
@Override
public void onPanelSlide(View panel, float slideOffset) {
// Change the dragview to panelheader when panel is fully expanded
// I'm doing this here instead of in onPanelExpanded,
// because onPanelExpanded first gets called once scroll
// is released.
if (slideOffset <= 0) {
slidePanel.setDragView(layoutPanelTop);
}
// If the panel is not fully expanded set the whole
// panel as dragview
else if(slideOffset > 0) {
slidePanel.setDragView(layoutPanel);
}
}
}
@Override
public void onPanelExpanded(View panel) {
// layout.setDragView(layoutPanelTop);
panelCollapsed = false;
panelExpanded = true;
panelAnchored = false;
Log.v("TAG, "panelExpanded");
}
@Override
public void onPanelCollapsed(View panel) {
slidePanel.setDragView(layoutPanel);
panelCollapsed = true;
panelExpanded = false;
panelAnchored = false;
Log.v(TAG, "panelCollapsed");
}
@Override
public void onPanelAnchored(View panel) {
slidePanel.setDragView(layoutPanel);
panelCollapsed = false;
panelExpanded = false;
panelAnchored = true;
Log.v(TAG, "panelAnchored");
}
});
我设法通过扩展滚动视图创建了一个完全工作的滚动视图侦听器,它可以检测滚动方向以及 onDown 和 onUp 运动事件:
private boolean atScrollViewTop = false;
@Override
public void onScrollChanged(int scrollY) {
scrollY = Math.min(mMaxScrollY, scrollY);
if (scrollY <= 0) {
Log.v("myTag", "You at scrollview top");
atScrollViewTop = true;
} else {
atScrollViewTop = false;
}
mScrollSettleHandler.onScroll(scrollY);
switch (mState) {
case STATE_SCROLL_UP:
if (panelExpanded && atScrollViewTop) {
slidePanel.setDragView(layoutPanel);
} else {
slidePanel.setDragView(layoutPanelTop);
}
Log.v("myTag", "scrolling up");
break;
case STATE_SCROLL_DOWN:
slidePanel.setDragView(layoutPanelTop);
Log.v("myTag", "scrolling down");
break;
}
}
@Override
public void onDownMotionEvent() {
}
@Override
public void onUpOrCancelMotionEvent() {
}
过去两天我一直在努力解决这个问题。所以真的希望至少有一些指针。首先十分感谢。问候雅各布·哈特格。