【问题标题】:onClick event on a SlidingDrawer not triggered未触发 SlidingDrawer 上的 onClick 事件
【发布时间】:2011-02-28 15:09:07
【问题描述】:

我创建了一个包含 ImageView 和 SlidingDrawer 的 RelativeLayout。我在 ImageView 上设置了一个 onClickListener,在 SlidingDrawer 的内容部分设置了另一个。当 SlidingDrawer 打开并点击它的内容部分时,会触发 ImageView 的 onClick 事件。

为什么?不是ImageView上面的SlidingDrawer吗?

谢谢

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="@drawable/background"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/whip"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" />  

    <SlidingDrawer
         android:id="@+id/drawer"
         android:layout_width="wrap_content"
         android:layout_height="53dp"
         android:layout_alignParentBottom="true"
         android:orientation="horizontal"

         android:handle="@+id/facebook_icon"
         android:content="@+id/facebook_contacts">

         <ImageView
             android:id="@+id/facebook_icon"
             android:layout_width="55dp"
             android:layout_height="53dp"         
             android:src="@drawable/facebook_handler_off" />

         <ImageView android:id="@+id/facebook_contacts"
                android:layout_width="265dp"
                android:layout_height="53dp"                
                android:src="@drawable/facebook_content" /> 

    </SlidingDrawer>

</RelativeLayout>

【问题讨论】:

  • 嘿,你有没有找到解决方案?我面临同样的问题,没有一个解决方案可以帮助我......

标签: android onclick slidingdrawer


【解决方案1】:

尝试通过执行来拦截鼠标事件 boolean onInterceptTouchEvent(MotionEvent 事件)

给文档,这个方法“拦截所有触摸屏运动事件”。

如果您想使用 SlidingDrawer 处理特定的 MotionEvent(提供参数),则返回 true。

看看onTouchEvent(MotionEvent event) :)

http://developer.android.com/reference/android/widget/SlidingDrawer.html#onInterceptTouchEvent(android.view.MotionEvent)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-31
    • 2013-04-30
    • 2011-02-05
    • 1970-01-01
    • 2014-08-11
    • 1970-01-01
    • 2013-03-12
    • 2013-07-01
    相关资源
    最近更新 更多