在ImageButton外部嵌套RelativeLayout时给RelativeLayout设置点击事件失灵,原因是RelativeLayout被ImageButton抢占了点击事件响应,可以将ImageButton改为ImageView解决。
<RelativeLayout
android:id="@+id/rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>