ImageButton from child layout onClick method not working
I have ImageButton on my View that is not working (method not called) when I try to click on it, but it is working if I click using the emulator keyboard. adb shell logcat doesn't print anything.
my main.xml layout:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/btn"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/ic_btn"
android:clickabl开发者_如何学运维e="true"
android:onClick="click"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Text" />
</LinearLayout>
</merge>
the click method in activity:
public void click(View view) {
tv.setText("clicked");
}
And if I put the ImageButton as direct child element of <merge>
, the click method is working. My build target is Android 2.2.
So, what is wrong here?
UPDATE I just know that this is because I have animation on the button, and location of the button is not updated after animation end. I didn't include that previously because I didn't know if it is related.
精彩评论