继续滚动时没有滚动可用就像在谷歌地图
问题描述:
我想复制使用AndroidSlidingUpPanel的谷歌地图。继续滚动时没有滚动可用就像在谷歌地图
我的问题是面板不能拖拽它就是列表视图中滚动。
正如你可以在谷歌地图中看到的。在面板完全展开之前,列表视图不可滚动。
<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>
贾森摹彼得森说
这是我在我的活动试图
更新
public class CustomListView extends ListView {
private boolean interceptTouch = true;
public void InterceptTouch(boolean bool) {
interceptTouch = bool;
}
public CustomListView(Context context) {
super(context);
}
public CustomListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CustomListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if(interceptTouch){
return false;
}else{
return super.onTouchEvent(ev);
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if(interceptTouch){
return false;
}else{
return super.onInterceptTouchEvent(event);
}
}
}
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);工作不正常,特别是当你快速滚动面板崩溃时。
我只想让面板在第一行显示并且用户向下滚动时折叠,就像拉动刷新效果一样。任何帮助?
// UPDATE 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.
}
我明白了。感谢这个想法。生病试试这个。 – Milk 2014-12-03 08:15:51
我试了一下。但有时它有效,有时不起作用 – Milk 2014-12-03 08:38:55