【发布时间】:2016-05-04 08:04:13
【问题描述】:
我在我的 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
我希望我的图像按钮每次都能正常工作。请帮忙。
【问题讨论】:
-
你为什么使用框架布局??
-
因为我需要将这两个按钮放在同一位置,但一次只需要显示一个。
-
你可以使用相对布局
-
但我不认为,这是由于框架布局。我也在其他 XML 中使用 ImageButton,它们没有像这样包裹在框架布局中,但它们仍然显示相同的行为。
-
第二个按钮的可见性消失了。你会怎么看
标签: android onclicklistener imagebutton