Issue
i am implementing an app which has some contents to show in webview. i am so far achieved smooth animation of scrolling webview contents using the object Animator.
Now what issue i am facing is that it is working fine for first and second page and scrolls as demand. but when i want to scroll on 3rd page what issue i have is that it starts scrolling from first page then moving to second and then to third i dont want this to happen i want is that webview should maintain its scroll position and scroll from the current position.
here is my code so far to make the webview contents scroll using objectanimator.
if (incre <= totalPages) {
incre++;
totalNumberofPages = totalNumberofPages + incre;
// view.loadUrl("javascript:pageScroll("
// + incre * view.getWidth() + ")");
ObjectAnimator anim = ObjectAnimator.ofInt(view,
"scrollX", 0, incre * view.getWidth());
anim.setDuration(4000);
anim.start();
// view.scrollTo(incre*view.getWidth(), 0);
anim.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animator animation) {
// TODO Auto-generated method stub
// view.scrollTo(0, incre*view.getWidth());
view.scrollTo(incre * view.getWidth(), 0);
ReaderActivity.txt_numberofpages_left
.setText("Page: " + incre + " of "
+ totalPages);
ReaderActivity.txt_leftPage.setText(""
+ totalNumberofPages);
ReaderActivity.txt_RightPage.setText(""
+ (totalNumberofPages + 1));
}
@Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
});
Solution
this is happening due to this line of code
ObjectAnimator anim = ObjectAnimator.ofInt(view,
"scrollX", 0, incre * view.getWidth());
anim.setDuration(4000);
anim.start();
after scrollX u are sending hardcoded 0 which will make your contents to scroll from start to the position maintain the last position and pass that position instead of this 0.
Answered By - user3729451
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.