Android 在没有滚动可用时继续滚动,就像在谷歌地图中一样
我正在尝试使用AndroidSlidingUpPanel复制谷歌地图 我的问题是面板不能拖动,只是listview正在滚动 正如你在谷歌地图中看到的那样。在面板完全展开之前,列表视图不可滚动Android 在没有滚动可用时继续滚动,就像在谷歌地图中一样,android,listview,android-listview,slidingmenu,Android,Listview,Android Listview,Slidingmenu,我正在尝试使用AndroidSlidingUpPanel复制谷歌地图 我的问题是面板不能拖动,只是listview正在滚动 正如你在谷歌地图中看到的那样。在面板完全展开之前,列表视图不可滚动 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="ht
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/app_secondary_color"
app:contentInsetLeft="14dp"
app:contentInsetRight="14dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"
android:gravity="bottom"
sothree:dragView="@+id/dragView"
sothree:panelHeight="140dp"
sothree:paralaxOffset="100dp"
sothree:shadowHeight="4dp">
<FrameLayout
android:id="@+id/maps_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<RelativeLayout
android:id="@+id/dragView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="false">
<ListView
android:id="@+id/hospital_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</RelativeLayout>
关于我的活动
mLayout.setPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
@Override
public void onPanelSlide(View view, float v) {
}
@Override
public void onPanelCollapsed(View view) {
LogUtil.d("COLLAPSED");
mListView.InterceptTouch(true);
}
@Override
public void onPanelExpanded(View view) {
LogUtil.d("EXPANDED");
mListView.InterceptTouch(false);
}
@Override
public void onPanelAnchored(View view) {
}
@Override
public void onPanelHidden(View view) {
}
});
问题是mListView.InterceptTouch(false);工作不正常,特别是在快速滚动面板时
我只希望面板在第一行首先显示并且用户向下滚动时折叠,就像拉动刷新效果一样。有什么帮助吗
//更新3
我加了这个。但当我拖动时,面板不会滑动。我需要再次拖动,然后面板滑动生效。为什么?
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
int cFirstVisibleItem = 0;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
interceptScroll(view);
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (view.getChildCount() > 0) {
cFirstVisibleItem = firstVisibleItem;
LogUtil.d("GET firstVisibleItem :" + firstVisibleItem);
LogUtil.d("GET Y :" + view.getChildAt(0).getY());
interceptScroll(view);
}
}
public void interceptScroll(AbsListView view) {
if (view.getChildAt(0).getY() == 0 && cFirstVisibleItem == 0) {
mLayout.setSlidingEnabled(true);
mListView.InterceptTouch(true);
LogUtil.d("intercept");
} else {
mListView.InterceptTouch(false);
mLayout.setSlidingEnabled(false);
LogUtil.d("dont intercept");
}
}
});
我怀疑这是因为ListView首先使用了触摸事件。您可以扩展ListView,然后使用以下代码段添加何时和何时不将触摸事件传递到滑动面板的条件:
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (/*Your conditions.*/) {
return false;//Don't intercept. Let sliding panel get touch.
}
return super.onInterceptTouchEvent(event); //Don't let sliding panel get touch.
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (/*Your conditions.*/) {
return false;//Don't intercept. Let sliding panel get touch.
}
return super.onInterceptTouchEvent(event); //Don't let sliding panel get touch.
}