我有一个带有以下适配器的ViewPager(页面是LinearLayouts):
MyPagerAdapter.kt
class MyPagerAdapter(private val activity: AppCompatActivity) : PagerAdapter()
{
private val pages = arrayOf(/* ... */)
override fun instantiateItem(container: ViewGroup, position: Int): Any
{
val inflater = LayoutInflater.from(activity)
val view = inflater.inflate(R.layout.my_layout, container, false) as LinearLayout
// add other views to `view`
return view
}
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any)
{
container.removeView(`object` as View)
}
override fun getPageTitle(position: Int): CharSequence?
{
return pages[position]
}
override fun isViewFromObject(view: View, `object`: Any): Boolean
{
return `object` == view
}
override fun getCount(): Int
{
return pages.size
}
}
显示软键盘后(例如,从另一个对话框中的EditText显示),ViewPager(或LinearLayout)不起作用:
removeViewAt
)中删除视图,该视图将消失,但其空间仍然存在addView
),则视图不会在底部添加或溢出,并且不可见 instantiateItem
并返回视图
但是它确实可以在分屏模式下工作
我尝试了使用除LinearLayout以外的其他片段和片段,它适用于某些视图,不适用于其他视图。这让我发疯了