2015-06-20 13 views
0

我有一个标准导航抽屉。这是一个ListView将自定义ImageView图标添加到导航抽屉会中断单击事件

 <ListView android:id="@+id/fragmentLeftDrawer" 
      android:layout_width="304dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:choiceMode="singleChoice" 
      android:divider="@android:color/transparent" 
      android:textStyle="bold" 
      android:dividerHeight="0dp"/> 

填充由drawer_list_item.xml

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:minHeight="?android:attr/listPreferredItemHeightSmall" 
    android:padding="10dp"> 

    <ImageView 
     android:id="@+id/navDrawerImageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:layout_centerVertical="true" 
     android:paddingStart="16dp" 
     android:paddingEnd="16dp"/> 

    <TextView 
     android:id="@+id/navDrawerTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_toEndOf="@+id/navDrawerImageView" 
     android:paddingStart="16dp" 
     android:paddingEnd="16dp"/> 

</RelativeLayout> 

这工作得很好。现在,我想用this Github project之类的东西替换ImageView。它基本上是一个自定义类,它扩展了ImageView。 (我的阶级是非常相似的链接项目,因此对于这个问题的目的,只是假定他们是相同的。)

如果我有这样的事情更换ImageViewdrawer_list_item.xml

<package.appname.CustomClass 
    android:id="@+id/navDrawerCustomImageView" 
    android:layout_width="48dp" 
    android:layout_height="48dp" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true" 
    android:layout_centerVertical="true" 
    android:paddingStart="16dp" 
    android:paddingEnd="16dp"/> 

那么,抽屉式导航栏将不会响应点击事件。它只会打开和关闭,但不会导航到应用程序的不同部分。没有错误或崩溃发生。

有谁知道为什么会发生这种情况?请告诉我。任何建议表示赞赏。

编辑:我应该提到,我也试过在我的自定义ImageView上切换android:clickable,看看它是否有任何效果,但不会产生差异。

+0

也许你'CustomClass'覆盖触摸逻辑(onClickListener,onTouchListener)。 –

+0

请说明你如何设置'onClickListener' –

+0

@EldarMensutov你可以看到我的自定义类的所有逻辑[here](https://github.com/markushi/android-circlebutton/blob/master/library/src/main/的java/AT/markushi/UI/CircleButton.java)。除了与当前问题无关的外观变化外,其行为与此项目非常相似。它只是覆盖'setPressed()'。对于'ListView',在我的主要活动中,我调用'mDrawerList.setOnItemClickListener(...)'。 – pez

回答

0

好吧,我似乎明白。 您在自己的自定义查看调用setClickable(true) 将其删除。

最短的解释here

+0

我以前在'xml'中设置了'android:clickable =“false”',但没有看到任何改进。可以肯定的是,我在'xml'中设置了一个新的'styleable''boolean'属性,我设置了'app:customview_clickable =“false”',然后在自定义视图代码中调用'setClickable(isClickable)'。但它仍然不起作用。不过谢谢你的想法。 – pez