LinearLayout中的点击监听器永远不会被调用 [英] LinearLayout's click listener is never called

查看:204
本文介绍了LinearLayout中的点击监听器永远不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图让一个onclick监听器工作在的LinearLayout,但其从来没有所谓:(启用可点击和focsuable(两种模式),仍然不能让点击听众响应平台详情:安卓3.0 ..任何帮助?以下

Trying to get an onclick listener working on a linearlayout but its never called :(. Have enabled clickable and focsuable (both modes) and still cant get the click listener to respond. Platform details: Android 3.0.. Any help?? Code below

           <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>

和在code添加事件监听器

and in the code to add the event listener

_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!
                }
            }
        );

我使用一个图像按钮这样做并不能代替的原因是因为键后台状态基于(梯度变化),而且该图像和为了结合于两个上点击/上焦点,我用的LinearLayout有本身就是一个ImageView的..为什么在clickListener不工作的的LinearLayout?

The reason I'm doing this and not using an Image button instead is because the background of the "button" is state based (gradient changes) but also the image and in order to combine to the two on click / on focus, I used a linearlayout which has an ImageView in itself.. any suggestions on why the clickListener is not working on the linearLayout?

THX

推荐答案

难道点击进入ImageView的,而不是LinearLayout中?尝试一下在垫区域(如果有的话),或者尝试将点击listenner的ImageView1。

Did the click go to the ImageView instead of the LinearLayout? Try clicking in the pad area (if any) or try putting the click listenner on the ImageView1.

这篇关于LinearLayout中的点击监听器永远不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆