【问题标题】:Bypassing stacked views with click listeners使用点击侦听器绕过堆叠视图
【发布时间】:2015-11-24 12:36:48
【问题描述】:

我有一个具有 ImageView 和 ViewPager 的 RelativeLayout。似乎 ViewPager 位于 ImageView 之上,因为我为 ImageView 设置了 onClick 侦听器,并且当我实现 ViewPager 时,ImageView 不再响应点击。有没有办法“点击”到下面的 ImageView?一般来说,是否可以忽略“顶”视图而让“底”视图响应点击事件?

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="15dp"
        android:layout_gravity="center_horizontal">

        <ImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/feed_image_content_description"
            android:scaleType="centerCrop" />        

         <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="500dp"
            android:scaleType="centerCrop">

            <android.support.v4.view.PagerTitleStrip
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                style="@style/custom_viewpagertitlestrip"
                android:layout_gravity="top" />

        </android.support.v4.view.ViewPager>
    </RelativeLayout>

【问题讨论】:

标签: java android imageview android-viewpager android-relativelayout


【解决方案1】:

您可能想尝试通过设置布局属性 android:clickable="false" 来告诉 ViewPage(及其子级)它们不可点击(我也可能从 XML 设置 android:focusable="false"android:focusableInTouchMode="false" 或从代码中调用 setClickable(false) .

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-29
    • 2023-02-02
    • 2021-01-21
    • 2019-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    相关资源
    最近更新 更多