从不调用LinearLayout的点击监听器
|
试图让onclick侦听器在线性布局上工作,但从未调用过:(。已启用clickable和focsuable(两种模式),但仍无法使Click侦听器响应。平台详细信息: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的linearlayout。有关clickListener为什么不能在linearLayout上工作的任何建议?
谢谢
没有找到相关结果
已邀请:
3 个回复
姬第柔炒
嗓瑰
草票
的宽度设置为\“ 0dip \”,屏幕上什么也看不到。 如果宽度更改为\“ FULL_PARENT \”,则可以。请再次仔细检查您的代码。