Próbuję zaimplementować prosty ViewPager z niektórymi animacjami na VectorDrawable.
Zgodnie z this very good example rozwiązanie dla ładnego przewijania kart z przełączaniem kropek.ViewPager z problemem TabLayout z AnimatedVectorDrawable
Jedyna różnica polega na tym, że używam animacji wektorowych. Jako działanie działa jak zaklęcie, z dodanym ViewPager, animacje są niezmiennie uruchamiane , a nie.
compileSdkVersion 25
buildToolsVersion "26.0.2"
targetSdkVersion 25
jestem debugowanie na urządzeniu (SG7), ustawić break-point na animation.start()
- na ekranie środkowym, break-point nie zawsze jest wywoływana
- częściej na ekranie 1 & 3, animacje nie są wyzwalane
- podczas skoków za pomocą kropek, między 1 & 3 animacje są zawsze wyzwalane! ale nie podczas 1-2 lub 2-3 !!
Wszystko to działa na jednym dużym VectorDrawable z 3 grupami, które są animowane.
2 napisy wsuwające się na początku, a następnie obracające się w nieskończoność, spin zawsze działa.
aktywny
@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;
}
Jestem nowy w tym wszystkim, chciał profil wpływu wielkości SVG (na wydajność myślenie o buforowaniu svg i wyzwalaniu animacji przy tworzeniu widoku może ...) i staram się zoptymalizować to wszystko i sprawiają, że jest gładka. Ale przede wszystkim nie działa poprawnie.
Dlaczego punkt przerwania nie zawsze jest trafiony podczas zamiany stron?
Czy istnieje lepszy sposób to zrobić?
Czy możesz opublikować "R.layout.activity_fullscreen" (który zawiera "AnimatedVectorDrawable", po prawej) i "Runnable"? – kalabalik
Wszystko czego potrzebowałem w tym przypadku to 'setUserVisibleHint (bool)' znalazłem to w tym temacie: [link] (https://stackoverflow.com/questions/10024739/how-to-determine-when-fragment-becomes-visible -in-viewpager? noredirect = 1 & lq = 1) – bua
Bez opublikowanego XML-a, skąd mamy wiedzieć? – kalabalik