【问题标题】:Dispatching GestureEvent (TouchEvent) to View in Viewpager在 Viewpager 中调度 GestureEvent (TouchEvent) 到视图
【发布时间】:2013-08-31 22:16:31
【问题描述】:

我有一个带有 SectionPagerAdapter 处理片段的 ViewPager。

片段有以下布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/tvemptyview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="@drawable/card_bg"
        android:text="@string/no_trans"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <ListView
        android:id="@+id/transactionlist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:divider="@null"
        android:dividerHeight="0dp" >
    </ListView>

    <RelativeLayout
        android:id="@+id/rLayout1"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:background="@drawable/footer_shadow"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/tvMonth"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/btn_dateback"
            android:text="test"
            android:textAppearance="?android:attr/textAppearanceMedium" />

    </RelativeLayout>

</RelativeLayout>

我试图在 TextView tvMonth 上捕捉滑动手势(向左或向右),但我完全不知道如何将事件从 ViewPager 分派到 TextView 本身。片段只是继续滚动,仅此而已。

我可以将 OnTouchListener 附加到 TextView 并且识别效果很好,但选项卡无论如何都会改变。

我该如何解决这个问题?

【问题讨论】:

标签: android touch android-viewpager gesture dispatch


【解决方案1】:

您应该在 textView 自身上设置 onClickListener 或 touchListener。然后touch事件会自动分派给TextView。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-01
    • 2021-04-24
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多