I have a ViewPager
fragment
class PagerFragment() : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val pagerView = view as ViewPager
val adapter = PagerAdapter(childFragmentManager, items)
pagerView.adapter = adapter
}
}
with the following adapter
class PagerAdapter(val fm: FragmentManager, val items: ArrayList<Item>)
: FragmentStatePagerAdapter(fm) {
override fun getItem(position: Int): Fragment {
val item = items[position]
return NestedFragment.newInstance(item)
}
override fun getCount(): Int {
return items.size
}
}
which nests fragments with a few animations triggered onViewCreated
the following way:
class NestedFragment() : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val one = AnimationUtils.loadAnimation(context, R.anim.one)
val two = AnimationUtils.loadAnimation(context, R.anim.two)
val three = AnimationUtils.loadAnimation(context, R.anim.three)
view.findViewById<ImageView>(R.id.pic).startAnimation(one)
view.findViewById<ConstraintLayout>(R.id.content).startAnimation(two)
view.findViewById<ImageView>(R.id.img).startAnimation(three)
}
}
However often by the time the nested fragment is showed on the screen the animation has already started or even ended :(
Is there a way to determine when the fragment is indeed rendered on the screen of the device? Of course any other useful suggestions to overcome the issue are welcome as well.