从不调用LinearLayout的click侦听器

Ric*_*ter 6 mobile android android-linearlayout android-3.0-honeycomb

试图让一个onclick监听器工作在linearlayout但它永远不会被调用:(.已启用可点击和focsuable(两种模式),仍然无法让点击监听器响应.平台详细信息: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>
Run Code Online (Sandbox Code Playgroud)

并在代码中添加事件监听器

_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!
                }
            }
        );
Run Code Online (Sandbox Code Playgroud)

我这样做而不使用图像按钮的原因是因为"按钮"的背景是基于状态的(渐变变化)而且是图像,并且为了在点击/焦点上组合两个,我使用了一个linearlayout本身就有一个ImageView ..有关为什么clickListener没有在linearLayout上工作的任何建议?

谢谢

pzu*_*ulw 5

点击是否转到ImageView而不是LinearLayout?尝试单击填充区域(如果有)或尝试将单击侦听器放在ImageView1上.

  • 我知道这已经很晚了,但你也可以将ImageView设置为不可点击的XML:`android:clickable ="false"` (4认同)