android - ViewPagerIndicator does not allow setBackgroundResource on ViewPager -
i'm trying use parallaxviewpager (https://github.com/andraskindler/parallaxviewpager) along viewpagerindicator (https://github.com/jakewharton/android-viewpagerindicator). problem i'm facing set background resource viewpager , works if not set page indicator. need viewpager indicator work parallaxviewpager.
the code i'm using
final parallaxviewpager parallaxviewpager = (parallaxviewpager) rootview.findviewbyid(r.id.authentication_opening_fragment_viewpager); pageindicator pageindicator = (circlepageindicator) rootview.findviewbyid(r.id.authentication_opening_fragment_indicator); parallaxviewpager.setadapter(new authenticationopeningpageadapter(context.getfragmentmanager())); parallaxviewpager.setbackgroundresource(r.drawable.bg_opening); pageindicator.setviewpager(parallaxviewpager);
if don't use last line, parallax background image works won't have indicator. if use .setviewpager() viewpager have blank background.
when debugging it, found "invalidates" setbackgroundresource line on viewpagerindicator library (on circlepageindicator file):
mviewpager.setonpagechangelistener(this);
is there workaround or can fix problem?
for work, need modify little on parallaxviewpager
this
private void init() { source = new rect(); destination = new rect(); scaletype = fit_height; overlap = overlap_half; listener = new pagechangeparallaxlistener(); setonpagechangelistener(listener); } public pagechangeparallaxlistener listener; public viewpager.onpagechangelistener getpagechangelistener() { return listener; } public class pagechangeparallaxlistener implements viewpager.onpagechangelistener { @override public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) { if (bitmap != null) { source.left = (int) math .floor((position + positionoffset - correction_percentage) * chunkwidth); source.right = (int) math .ceil((position + positionoffset + correction_percentage) * chunkwidth + projectedwidth); destination.left = (int) math .floor((position + positionoffset - correction_percentage) * getwidth()); destination.right = (int) math.ceil((position + positionoffset + 1 + correction_percentage) * getwidth()); invalidate(); } if (secondonpagechangelistener != null) { secondonpagechangelistener.onpagescrolled(position, positionoffset, positionoffsetpixels); } } @override public void onpageselected(int position) { if (secondonpagechangelistener != null) { secondonpagechangelistener.onpageselected(position); } } @override public void onpagescrollstatechanged(int state) { if (secondonpagechangelistener != null) { secondonpagechangelistener.onpagescrollstatechanged(state); } } }
and while implementing circlepageindicator
, have this
parallaxviewpager viewpager; circlepageindicator circlepageindicator; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(your layout); //do view initialization id viewpager.setadapter(your adapter); circlepageindicator.setonpagechangelistener(viewpager .getpagechangelistener()); circlepageindicator.setviewpager(viewpager); viewpager.setbackgroundresource(r.drawable.parallax_bg); }
Comments
Post a Comment