首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ListView在SlidingPaneLayout内部

ListView在SlidingPaneLayout内部
EN

Stack Overflow用户
提问于 2015-01-26 17:04:47
回答 1查看 647关注 0票数 2

我有这样的活动布局:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<SlidingPaneLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/course_menu_sliding_layout"
   android:layout_width="match_parent"
   android:background="@color/white"
   android:layout_height="match_parent">

   <!-- Here is any view that will represent your side menu. Don't forget to provide width! -->
   <FrameLayout
       android:id="@+id/course_activity_menu"
       android:layout_width="@dimen/edu5_menu_width"
       android:layout_height="match_parent"
       android:background="@color/white"
       android:layout_gravity="start" />


   <RelativeLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent">

       <FrameLayout
           android:id="@+id/courseActivityNavigationController"
           android:layout_width="match_parent"
           android:layout_height="@dimen/edu5_navigation_controller_height"
           />

       <FrameLayout
           android:id="@+id/courseActivityContentFragmentContainer"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="@color/c_popup_bg"
           android:layout_below="@id/courseActivityNavigationController"
           />

   </RelativeLayout>
</SlidingPaneLayout>

现在,在id为“FrameLayout”的“courseActivityContentFragmentContainer”上,我添加了一个‘片段’,其中一个在视图布局中包含了一个'ListView‘。

问题是,当我滚动列表时,它开始滚动,然后'SlidingPaneLayout‘控制并滑动窗格布局。

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-28 09:19:09

我找到的解决方案是扩展“SlidingPaneLayout”,并将“ListView”中可见的矩形传递给它,这样就不会拦截“ListView”中的触摸事件。

下面是代码:

代码语言:javascript
复制
public class MySlidingPaneLayout extends SlidingPaneLayout {
    private Rect mIgnoreRect;
    ...
    ...
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if ( !isOpen() && mIgnoreRect != null && mIgnoreRect.contains((int)ev.getX(), (int)ev.getY()) )
        {
            return false;
        }
        try
        {
            return super.onInterceptTouchEvent(ev);
        }
        catch ( Exception ex )
        {
            Log.e(TAG, "super.onInterceptTouchEvent threw exception", ex);
        }
        return false;
    }
}

顺便说一句,我试着去抓,因为有时会抛出一个'NullPointerException‘,我找不到原因。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28155027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档