尝试让 onclick 侦听器在线性布局上工作,但它从未被调用:(。已启用可点击和可聚焦(两种模式),但仍然无法让点击侦听器响应。平台详细信息:Android 3.0..有任何帮助吗?下面的代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu_items_button"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center_horizontal"
android:paddingTop="@dimen/gen_margin_xsmall"
android:paddingBottom="@dimen/gen_margin_xsmall"
android:background="@drawable/rule_bg_menu_button"
android:clickable="true"
android:focusableInTouchMode="true"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu_items"
android:tag="image"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="text"
android:text="@string/menu_items_icon_txt"
style="@style/textDisplay.mediumLarge"
/>
</LinearLayout>
并在代码中添加事件监听器
_itemsButton = (LinearLayout) menu.findViewById(R.id.menu_items_button);
final Intent itemsIntent = new Intent(this, ItemsActivity.class);
_itemsButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(itemsIntent); //Never called!
}
}
);
我这样做而不使用图像按钮的原因是因为“按钮”的背景是基于状态的(渐变变化),而且也是图像,为了在单击/聚焦时将两者结合起来,我使用了本身有一个 ImageView 的线性布局。关于为什么 clickListener 不能在线性布局上工作有什么建议吗?
thx
单击是否转到 ImageView 而不是 LinearLayout?尝试单击 pad 区域(如果有)或尝试将单击侦听器放在 ImageView1 上。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)