I am simply using a PNG image as source in ImageView
& want to add a onClickListener()
. Problem is that button's onClick()
doesn't trigger smoothly, means when I click on image sometimes it works fine & sometimes it doesn't work. Even I have added some padding around ImageView to increase the clickable area. I also tried replacing ImageView
with ImageButton
but no luck. That is also behaving same way.
Here is my code:
ImageView back = (ImageView) findViewById(R.id.back);
back.setOnClickListener(new View.OnClickListener()
{
public void onClick(final View v)
{
finish()
}
});
XML for button:
<ImageView
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:padding="10dp"
android:src="@drawable/btn_back"/>
Please note that I am using this ImageView
in a custom action bar.
getSupportActionBar().setDisplayHomeAsUpEnabled(true);