Framelayout onclick中的ImageView仅在第二次单击时触发

时间:2014-09-23 13:21:43

标签: android imageview onclicklistener

所以我在这里搜索了很多解决方案,但没有一个能为我工作。

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@+id/leftFrame"
    android:focusable="false"
    android:focusableInTouchMode="false" >

    <ImageView
        android:id="@+id/mark_as_complete"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="30dp"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:src="@drawable/immunisation_select_all_btn" />
    <TextView
        android:id="@+id/markAllText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="10dp"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="@string/mark_as_completed"
        android:textColor="@color/immunisation_button_text_color" />
</FrameLayout>

这些内容包含在RelativeLayout中,LinearLayout位于ImageView markAsComplete = (ImageView) findViewById(R.id.mark_as_complete); markAsComplete.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //Do something fun } }); ,所有 <FrameLayout android:layout_width="fill_parent" android:layout_height="40dp" android:layout_alignParentRight="true" android:layout_toRightOf="@+id/leftFrame" android:focusable="false" android:focusableInTouchMode="false" > <ImageView android:id="@+id/mark_as_complete" android:layout_width="fill_parent" android:layout_height="40dp" android:clickable="true" android:layout_marginLeft="30dp" android:focusable="true" android:focusableInTouchMode="true" android:src="@drawable/immunisation_select_all_btn" /> <TextView android:id="@+id/markAllText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginTop="10dp" android:focusable="false" android:focusableInTouchMode="false" android:text="@string/mark_as_completed" android:textColor="@color/immunisation_button_text_color" /> </FrameLayout> 都具有禁用焦点的属性

这是onclick代码。它只适用于第二次点击

<FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/leftFrame"
        android:focusable="false"
        android:focusableInTouchMode="false" >

        <ImageView
            android:id="@+id/mark_as_complete"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:clickable="true"
            android:layout_marginLeft="30dp"
            android:focusable="true"
            android:focusableInTouchMode="false"
            android:src="@drawable/immunisation_select_all_btn" />

        <TextView
            android:id="@+id/markAllText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="10dp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="@string/mark_as_completed"
            android:textColor="@color/immunisation_button_text_color" />
    </FrameLayout>

更新:

我尝试过以下操作,但仍然无法正常工作

<FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/leftFrame"
        android:focusable="false"
        android:focusableInTouchMode="false" >

        <ImageView
            android:id="@+id/mark_as_complete"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:clickable="true"
            android:layout_marginLeft="30dp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:src="@drawable/immunisation_select_all_btn" />

        <TextView
            android:id="@+id/markAllText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="10dp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="@string/mark_as_completed"
            android:textColor="@color/immunisation_button_text_color" />
    </FrameLayout>

{{1}}

{{1}}

由于

2 个答案:

答案 0 :(得分:1)

问题最终导致getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);导致活动的第一次触摸被拦截以再次显示导航项目。我现在正在使用此answer

建议的getWindow().getDecorView().setSystemUiVisibility(View.Gone);

答案 1 :(得分:0)

也许是因为您禁用了ImageView的焦点? (只是一个想法)

相关问题