我在xml中使用ImageButton,像这样:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton_home"
android:src="@drawable/home_icon"
android:background="@android:color/transparent"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:focusableInTouchMode="false"
android:focusable="false"
android:clickable="true"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton_back"
android:src="@drawable/back_icon"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:background="@android:color/transparent"
android:visibility="gone"
android:focusableInTouchMode="false"
android:focusable="false"
android:clickable="true"
/>
</FrameLayout>
每次只有一个图片按钮可见。 在我的Java代码中,我如下捕获点击事件:
imageButtonHome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent homeIntent = new Intent(SettingsActivity.this, MainActivity.class);
startActivity(homeIntent);
}
});
有时候可以正常工作,但并非总是如此。 每当我点击图像按钮时,在我的logcat中都会看到这行代码:
D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
即使我的ImageButton点击操作没有执行,这一行始终会显示出来。
但是当我的ImageButton点击正常工作时,另一行会添加到日志中:
D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
D/AbsListView: Get MotionRecognitionManager
我想让我的图像按钮每次都能正常工作。请帮帮我。