首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓、SlidingPaneLayout和listView

安卓、SlidingPaneLayout和listView
EN

Stack Overflow用户
提问于 2013-06-17 04:52:00
回答 4查看 4.1K关注 0票数 5

在我的SlidingPaneLayout.The主视图中,我使用了一个ListView作为辅助视图,它是一个地图片段。ListView充当菜单。问题是在ListView上永远不会调用onItemClickedListener。即使是列表行在印刷机上也不会突出显示。看起来ListView不能获得焦点。

编辑:实际上,slidingPaneLayout.findFocus()显示的是android.widget.ListView。单击列表项时仍然没有结果。

下面是我的xml

代码语言:javascript
复制
<com.ziz.luke.custom_components.MySlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/contactsList"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#00000000" >
    </ListView>

    <TextView
        android:id="@+id/android:empty"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center_horizontal|center_vertical"
        android:text="@string/noContacts" />
</RelativeLayout>

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />
</com.ziz.luke.custom_components.MySlidingPaneLayout>

我怎么才能解决这个问题呢?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-06-19 08:08:05

我找到了答案。我使用的是SlidingPaneLayout的一个子类,其中我重写了

代码语言:javascript
复制
onInterceptTouchEvent(MotionEvent arg0)

我试着做以下几件事:

  • 使用按钮打开slidingPaneLayout。
  • 使用按钮关闭slidingPaneLayout。
  • close slidingPaneLayout using swiping.
    • prevent

    user using the the slidingPaneLayout the using swiping。

因此,我在名为shouldSwipe的子类中创建了一个布尔值,以便从覆盖的方法返回。

导致问题的实现是:

代码语言:javascript
复制
@Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {

        return shouldSwipe;
    }

无论何时(shouldSwipe = true),它都会导致问题,因为它会告诉系统触摸事件已经被使用,并阻止它被传播。

我用这个解决了这个问题:

代码语言:javascript
复制
@Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return shouldSwipe ?super.onInterceptTouchEvent(arg0):shouldSwipe;
    }

就这样。

票数 6
EN

Stack Overflow用户

发布于 2013-06-19 07:43:14

我刚刚使用SlidingPaneLayout创建了一个示例项目。

我没有使用任何地图,因为没有问题所在,所以我只是使用TextView来引用地图的位置。我确实使用了一个工作正常并接收点击监听程序的ListFragment。请从此处下载该项目:

https://dl.dropboxusercontent.com/u/33565803/StackOverFlowExamples/SlidingPaneLayoutExample.zip

如果您有任何配置问题,请让我知道它是否解决了您的问题;)

(我使用actionBarSherlock只是因为我习惯了,所以如果你愿意,你可以删除它)

票数 3
EN

Stack Overflow用户

发布于 2013-06-25 00:10:56

这只是一个建议,但也许使用NavigationDrawer作为导航列表抽屉会比重新发明轮子更容易。

http://developer.android.com/design/patterns/navigation-drawer.html

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

https://stackoverflow.com/questions/17137582

复制
相关文章

相似问题

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