I'm trying to implement simple ViewPager with some animations on VectorDrawable.
Following this very good example solution for nice tab scrolling with dot's switching.
The only difference is that I'm using vector animations. As an activity it works like a charm, with ViewPager added, animations are not started consistently.
compileSdkVersion 25
buildToolsVersion "26.0.2"
targetSdkVersion 25
I'm debugging on my device (SG7), I set break-point on animation.start()
- on the middle screen, break-point is not always invoked
- more often on screen 1 & 3, animations are not triggered
- when jumping using dots, between 1&3 animations are always triggered! but not when doing 1-2 or 2-3 !!
All this is working on one big VectorDrawable with 3 groups which are animated.
2 captions sliding in on start, and then is infinitely rolling spin, spin always work.
Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mHideHandler.post(mHidePart2Runnable);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabDots);
tabLayout.setupWithViewPager(mViewPager, true);
};
Fragment:
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
return PlaceholderFragment.newInstance(position + 1);
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
Static Fragment
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
public PlaceholderFragment() {
}
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_fullscreen, container, false);
View imgView = rootView.findViewById(R.id.vec_anim);
Drawable drawable = ((ImageView)imgView).getDrawable();
if (drawable instanceof Animatable) {
((Animatable) drawable).start();
};
return rootView;
}
I'm new to all of this, wanted to profile the impact of SVG size on performance (thinking of caching svgs and triggering animations on view creation maybe...) and I'm trying to optimize it all and make it smooth. But first of all, it doesn't work properly.
Why is breakpoint not always hit when swapping pages?
Is there any better way of doing this?