onClick not triggered on LinearLayout with child

后端 未结 15 1066
生来不讨喜
生来不讨喜 2020-11-29 03:33

I\'ve got a custom LinearLayout with a smaller TextView child. I\'d like to be able to click the area not covered by the TextView, so I set clickable=true and an onclicklist

相关标签:
15条回答
  • 2020-11-29 04:00

    One thing to make sure of is that another view is not on top of the view you are trying to click. This is especially common in FrameLayouts (where your sub LinearLayout may be covered) or with Relative Layouts you might have forgot to update this line:

    android:layout_below="@id/shouldBeTheIdOfTheViewCurrentlyBeingCovered"
    

    so that views don't fill the same space.

    0 讨论(0)
  • 2020-11-29 04:01

    You aren't using your custom View; you're using a standard LinearLayout. Your XML tag should be:

    <com.yourcode.ARView ...> ... </com.yourcode.ARView>
    
    0 讨论(0)
  • 2020-11-29 04:03

    Add the following attributes to the linearlayout Any Click events not handled by the child views will be automatically passed over to the LinearLayout.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        ...
        android:focusable="true"
        android:clickable="true">
    
    <child/>
    <child/>
    
    </LinearLayout>
    
    0 讨论(0)
提交回复
热议问题