I have a number of ImageButtons
in a layout. The image resources are 32x32 px. They all have the same attributes:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ibButton1"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_weight="0"
android:src="@drawable/not_selected"
android:layout_gravity="center_vertical"
android:background="@null"/>
In my fragment, I'm doing:
final ImageButton button1 = (ImageButton)view.findViewById(R.id.ibButton1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isSelected = !isSelected;
if (isSelected ) {
button1.setImageResource(R.drawable.selected);
}
else {
button1.setImageResource(R.drawable.not_selected);
}
}
});
However, most times I need to click over 5 times on the button for it to register the click.
Should I need to increase the image size or is there a better way to listen to clicks? Should I use onClick
attribute instead?
Provide some padding to increase the Tap area.