我的應用的觸摸區域使用下列ViewPager
:來擴展ViewPager
ViewPager
的具有相同的寬度顯示。
我添加利潤率的ViewPager在XML中,這樣我可以看到左(藍色)和右(灰色)頁面。 因此,一切正常,但我只能觸摸到綠色區域來移動頁面。
我想擴大觸摸區域到整個屏幕,以便我能夠隨時隨地觸及到移動ViewPager
。
我嘗試添加TouchDelegate
:
binding.pagerContainer.post {
val rect = Rect()
binding.touchArea.getHitRect(rect)
binding.pagerContainer.touchDelegate = TouchDelegate(rect, binding.viewPager)
}
並且XML:
<FrameLayout
android:id="@+id/pager_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:clipChildren="false">
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="150dp"
android:layout_marginLeft="70dp"
android:layout_marginRight="70dp"
android:layout_marginTop="150dp"
android:clipChildren="false"/>
<View
android:id="@+id/touchArea"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0">
</View>
</FrameLayout>
的Rect
具有正確的尺寸。 我發佈Runnable
以確保視圖已佈置。 我閱讀了TouchDelegate
的文檔。
我不知道爲什麼它不起作用。
天才!愛你:) – Appyx
它肯定有幫助,如果我讀完整個問題:) – Gary99