Android: แอนิเมชันการเลื่อน WebView

ฉันกำลังใช้งานแอปซึ่งมีเนื้อหาบางส่วนที่จะแสดงใน webview จนถึงตอนนี้ ฉันได้รับแอนิเมชั่นที่ราบรื่นในการเลื่อนเนื้อหา webview โดยใช้ object Animator

ตอนนี้ปัญหาที่ฉันกำลังเผชิญคือมันทำงานได้ดีสำหรับหน้าแรกและหน้าที่สองและเลื่อนได้ตามความต้องการ แต่เมื่อฉันต้องการเลื่อนไปที่หน้าที่ 3 ฉันมีปัญหาอะไรคือมันเริ่มเลื่อนจากหน้าแรก จากนั้นเลื่อนไปยังหน้าที่สองและสาม ฉันไม่ต้องการให้สิ่งนี้เกิดขึ้น ฉันต้องการคือ webview ควรรักษาตำแหน่งการเลื่อนไว้และเลื่อนจากหน้าปัจจุบัน ตำแหน่ง.

นี่คือรหัสของฉันเพื่อให้เนื้อหา webview เลื่อนโดยใช้ 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

                        }
                    });

person Umer Kiani    schedule 27.07.2014    source แหล่งที่มา


คำตอบ (1)


สิ่งนี้เกิดขึ้นเนื่องจากบรรทัดของโค้ดนี้

  ObjectAnimator anim = ObjectAnimator.ofInt(view,
                        "scrollX", 0, incre * view.getWidth());
                anim.setDuration(4000);
                anim.start();

หลังจาก scrollX คุณกำลังส่งฮาร์ดโค้ด 0 ซึ่งจะทำให้เนื้อหาของคุณเลื่อนจากจุดเริ่มต้นไปยังตำแหน่งคงตำแหน่งสุดท้ายและส่งผ่านตำแหน่งนั้นแทนที่จะเป็น 0 นี้

person Community    schedule 29.07.2014