这是控件代码
<ImageView
android:id="@+id/avin_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10px"
android:background="@drawable/avin_default"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true" />
其中android:clickable="true"是设置控件可以被点击,也就是可以有onclick事件
android:focusable="true"是设置控件可以获取焦点,也就是可以有onfocuschanage事件
android:focusableInTouchMode="true"是通过触摸来获取焦点
所以当我们要去执行当前控件的onclick事件时候,就会先让控件获取焦点,然后再次点击才会执行onclick事件,也就是笔者写的标题点击两次才会执行onclick事件
解决办法:去掉android:focusableInTouchMode="true"属性即可