底部对话框底部的viewpager中看不到片段

时间:2019-08-16 18:52:38

标签: android android-layout android-fragments android-viewpager

我正在BottomSheetDialog内的viewpager内使用片段,但是片段是不可见的,所以我的XML没有问题,因为如果我使用PagerAdapter,则它们是可见的。

适配器

    class TipsPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
        override fun getCount(): Int {
            return 3
        }

        override fun getItem(position: Int): Fragment? {
            when (position) {
                0 -> return TipsFragment1() //ChildFragment1 at position 0
                1 -> return TipsFragment2() //ChildFragment2 at position 1
                2 -> return TipsFragment3() //ChildFragment3 at position 2
            }
            return null //does not happen
        }
    }

对话框

     val bottomSheetDialog = BottomSheetDialog(it)
                val tipsBinding = DataBindingUtil.inflate<DialogTipsBottomSheetBinding>(
                    LayoutInflater.from(it),
                    R.layout.dialog_tips_bottom_sheet,
                    null,
                    false
                )
                bottomSheetDialog.setContentView(tipsBinding.root)
// I BELIEVE PROBLEM IS HERE
                tipsBinding.viewPager.adapter = TipsPagerAdapter(mainActivity?.supportFragmentManager!!) 
                tipsBinding.viewPager.offscreenPageLimit = 2
                tipsBinding.pagerIndicators.setupWithViewPager(tipsBinding.viewPager, true)

片段

class TipsFragment1 : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.tips_one, container, false)
    }

    companion object {
        fun newInstance(): TipsFragment1 {
            return TipsFragment1()
        }
    }
}

0 个答案:

没有答案