onClick not triggered on LinearLayout with child

后端 未结 15 1106
生来不讨喜
生来不讨喜 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 03:43

    I faced the same problem, and all the XML attributes didn't work. I think this happens because I programmatically inflate and add the views. The fix for me was to - also that programatically - set the inflated root view not clickable:

    View view = layoutInflater.inflate(R.layout.some_layout, someLinearLayout, false);
    view.setClickable(false);
    

    (Yes, I tried to have the some_layout not clickable in XML.)

提交回复
热议问题