与ViewPager一起使用时,ImageView无法检测到点击次数

时间:2012-09-05 17:53:20

标签: android onclick android-viewpager android-imageview

我有以下XML文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/welcome_bg" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/arrowLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|left"
            android:layout_marginLeft="10dp"
            android:clickable="true"
            android:contentDescription="@string/arrow_left"
            android:focusable="true"
            android:src="@drawable/arrow_left"
            android:visibility="invisible" />

        <ImageView
            android:id="@+id/arrowRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|right"
            android:layout_marginRight="10dp"
            android:clickable="true"
            android:contentDescription="@string/arrow_right"
            android:focusable="true"
            android:src="@drawable/arrow_right" />

        <android.support.v4.view.ViewPager
            android:id="@+id/tutorialViewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>

</RelativeLayout>

我的问题是,当用户点击左箭头或右箭头时,寻呼机应该翻转,但我无法在leftarrow或rightarrow ImageView上获得点击事件。单击箭头时,我无法获得该事件。我在两个箭头上都设置了onClickListeners,但它们从未被调用过。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:1)

我明白了。我必须使用rightArrow.bringToFront()leftArrow.bringToFront()。这使得按钮位于前面,我可以在它们上面获得点击事件。