android - LinearLayout (with onClick) containing ImageButton - 有没有更好的方法来解决它?

标签 android android-layout android-linearlayout

目前我有这样的事情:

<LinearLayout android:layout_height="80dip" android:id="@+id/linearLayoutSettings"
 android:layout_width="80dip" android:orientation="vertical">

    <ImageButton android:layout_height="wrap_content" android:src="@android:drawable/ic_menu_manage" 
android:id="@+id/imageButton1" android:layout_width="wrap_content"></ImageButton>

</LinearLayout>

LinearLayout 附加了 onClick 监听器。

问题:当在 LinearLayout 中单击 ImageButton 时,事件不会被触发。

我可以通过将与我附加到 LinearLayout 时相同的点击附加到此按钮来解决它。但在那种情况下,这将意味着很多重复代码(有很多按钮)。

问题:有没有更有效的方法解决这个问题?

最佳答案

将 ImageButton 更改为 ImageView,您将开始获取点击事件

关于android - LinearLayout (with onClick) containing ImageButton - 有没有更好的方法来解决它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7053189/

相关文章:

android - 如何为 API 级别 8 到 19 的 android 设备同时使用 DigitalClock 和 TextClock?

java - 如何在Android上实现持久化队列

Android API 21 忽略 layout_marginEnd 并在 EditText 中使用 layout_marginRight

android - 如何在 Android 中使线性布局可滚动和可缩放?

java - View.Gone 位于适配器内部,在 onBindViewHolder 中留下空间

Android:什么时候使用layout_margin,什么时候使用weightSum?

android - 算法:停止无效条目进入 python 脚本中的竞赛

android - 应用程序被终止时 Android 中的信标检测

android - AlertDialog vs Spinner vs ListView

android - 如何激活 TextView 上的文本选取框?