我的应用程序使用以下的
我在xml中为
我想将触摸区域扩展到整个屏幕,这样我就可以在任何地方触摸来移动
我尝试添加
ViewPager
:
ViewPager
的宽度与显示屏相同。我在xml中为
ViewPager
添加了边距,以便我可以看到左侧(蓝色)和右侧(灰色)的页面。结果一切正常,但是我只能点击绿色区域来移动页面。我想将触摸区域扩展到整个屏幕,这样我就可以在任何地方触摸来移动
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
的文档。
我不知道为什么它不起作用。