As you can see, The viewpager is invisible after i scroll it.
It's truly weird.
This is my PaggerAdapter and onPageChangeListener.
mVideos.forEachIndexed { _, _ ->
mVideoFragments.add(layoutInflater.inflate(R.layout.homepage_videoview_fragment, null))
}
mBinding.wholeScreenViewpager.adapter = object : PagerAdapter() {
override fun instantiateItem(container: ViewGroup, position: Int): Any {
val v = mVideoFragments[position]
container.addView(v)
return v
}
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
container.removeView(`object` as View)
}
override fun getCount(): Int {
return mVideoFragments.size
}
override fun isViewFromObject(view: View, `object`: Any): Boolean {
return view == `object`
}
}
mBinding.wholeScreenViewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {
}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
(requireActivity() as DeepModeService).reset()
}
override fun onPageSelected(position: Int) {
Timber.tag("homepage").d("selected position $position")
// mPlayer.playRecord(true, mAudios[position], true, isPlay = mPlayer.isPlaying())
}
})
This is my layout
<?xml version="1.0" encoding="utf-8"?>
My ViewPager.
class WholeScreenViewPager(context: Context, attrs: AttributeSet?) : ViewPager(context, attrs) {
private val mScreenWidth by lazy {
val displayMetrics = DisplayMetrics()
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
windowManager.defaultDisplay.getRealMetrics(displayMetrics)
displayMetrics.widthPixels
}
private val mScreenHeight by lazy {
val displayMetrics = DisplayMetrics()
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
windowManager.defaultDisplay.getRealMetrics(displayMetrics)
displayMetrics.heightPixels
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
Timber.tag("VIDEO").d("$mScreenWidth $mScreenHeight")
setMeasuredDimension(mScreenWidth, mScreenHeight)
}
}
Есть идеи? Сначала спасибо.