0
我想複製使用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");
}
}
});
我明白了。感謝這個想法。生病試試這個。 – Milk 2014-12-03 08:15:51
我試了一下。但有時它有效,有時不起作用 – Milk 2014-12-03 08:38:55