我使用以下代码更改viewpager中滑动的默认速度。我尝试使用Java代码,此stackoverflow问题的帮助。我使用以下Kotlin代码设置自动滑动视图pager
的动画极限val mScroller = ViewPager::class.java.getDeclaredField("mScroller");
mScroller.setAccessible(true);
val scroller = Scroller(requireContext(), DecelerateInterpolator());
mScroller.set(mPager, scroller);
但不适合Kotlin工作的代码,并给出此崩溃
05-08 19:21:59.690 23859-23859/com.mindfulness.greece A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 23859 (dfulness.greece)
05-08 19:21:59.820 7677-7677/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
05-08 19:21:59.820 7677-7677/? A/DEBUG: Build fingerprint: 'Android/sdk_google_phone_x86/generic_x86:6.0/MASTER/5056751:userdebug/test-keys'
05-08 19:21:59.820 7677-7677/? A/DEBUG: Revision: '0'
05-08 19:21:59.820 7677-7677/? A/DEBUG: ABI: 'x86'
05-08 19:21:59.821 7677-7677/? A/DEBUG: pid: 23859, tid: 23859, name: dfulness.greece >>> com.mindfulness.greece <<<
05-08 19:21:59.821 7677-7677/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
05-08 19:21:59.830 7677-7677/? A/DEBUG: eax 00000000 ebx b5ba0398 ecx 00000002 edx 00000000
05-08 19:21:59.831 7677-7677/? A/DEBUG: esi 9b6bd6bc edi 00000028
05-08 19:21:59.831 7677-7677/? A/DEBUG: xcs 00000073 xds 0000007b xes 0000007b xfs 00000007 xss 0000007b
05-08 19:21:59.831 7677-7677/? A/DEBUG: eip b5b111d0 ebp bf742000 esp bffa6030 flags 00210286
05-08 19:21:59.832 7677-7677/? A/DEBUG: backtrace:
05-08 19:21:59.832 7677-7677/? A/DEBUG: #00 pc 0002a1d0 /system/lib/libhwui.so
05-08 19:21:59.832 7677-7677/? A/DEBUG: #01 pc 0003e9eb /system/lib/libhwui.so (android::uirenderer::DisplayListCanvas::drawCircle(float, float, float, SkPaint const&)+251)
05-08 19:21:59.832 7677-7677/? A/DEBUG: #02 pc 000d581c /system/lib/libandroid_runtime.so
05-08 19:21:59.833 7677-7677/? A/DEBUG: #03 pc 737055f0 /data/dalvik-cache/x86/system@framework@boot.oat (offset 0x1eb2000)
05-08 19:21:59.833 7677-7677/? A/DEBUG: #04 pc 00002ca3 /system/lib/libhwui.so (offset 0xb3000)
05-08 19:21:59.833 7677-7677/? A/DEBUG: #05 pc 0003a193 /system/lib/libhwui.so (non-virtual thunk to android::uirenderer::DisplayListCanvas::~DisplayListCanvas()+9)
05-08 19:21:59.833 7677-7677/? A/DEBUG: #06 pc 0003a20f /system/lib/libhwui.so
05-08 19:21:59.833 7677-7677/? A/DEBUG: #07 pc 027010eb [heap]
05-08 19:21:59.980 7677-7677/? A/DEBUG: Tombstone written to: /data/tombstones/tombstone_05
05-08 19:21:59.981 7677-7677/? E/DEBUG: AM write failed: Broken pipe
05-08 19:22:00.100 1640-1696/system_process E/InputDispatcher: channel 'eb88da6 com.mindfulness.greece/com.mindfulness.greece.activity.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
05-08 19:22:00.191 1640-6583/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
05-08 19:22:00.192 1640-6583/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
05-08 19:22:00.192 1640-6583/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
05-08 19:22:00.259 1955-2211/com.android.launcher3 E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
05-08 19:22:00.259 1955-2211/com.android.launcher3 E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
05-08 19:22:00.260 1955-2211/com.android.launcher3 E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
您可以看到它,我认为它会帮助您...
private fun init() {
mPager = findViewById(R.id.pager) as ViewPager
mPager!!.adapter = SlidingImage_Adapter(this@MainActivity, this.imageModelArrayList!!)
val indicator = findViewById(R.id.indicator) as CirclePageIndicator
indicator.setViewPager(mPager)
val density = resources.displayMetrics.density
//Set circle indicator radius
indicator.setRadius(5 * density)
NUM_PAGES = imageModelArrayList!!.size
// Auto start of viewpager
val handler = Handler()
val Update = Runnable {
if (currentPage == NUM_PAGES) {
currentPage = 0
}
mPager!!.setCurrentItem(currentPage++, true)
}
val swipeTimer = Timer()
swipeTimer.schedule(object : TimerTask() {
override fun run() {
handler.post(Update)
}
}, 3000, 3000)
// Pager listener over indicator
indicator.setOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageSelected(position: Int) {
currentPage = position
}
override fun onPageScrolled(pos: Int, arg1: Float, arg2: Int) {
}
override fun onPageScrollStateChanged(pos: Int) {
}
})
}
companion object {
private var mPager: ViewPager? = null
private var currentPage = 0
private var NUM_PAGES = 0
}