2016-08-30 57 views
0

我想創建一個動畫,以便在我的滾動視圖中自動滾動。ObjectAnimator持續時間不被尊重

LinearLayout linearLayout = (LinearLayout) scrollView.getChildAt(0); 
// linearLayout.getHeight() == 540 
animScroll = ObjectAnimator.ofInt(scrollView, "scrollY", linearLayout.getHeight()); 

// animationDurationLong == 154000 
animScroll.setDuration(animationDurationLong); 
animScroll.setInterpolator(new LinearInterpolator()); 

animScroll.start(); 

我的動畫工作完美,我從我的滾動視圖內容到頂部到底部滾動,但我是96秒,而不是持續時間設定154秒。

有誰知道爲什麼?我檢查了我的手機的開發者設置,嘗試了兩種設備,仍然是同樣的問題。

+0

ofInt'的'最後一個參數是錯誤的,你需要:'內容高度 - 容器height' – pskink

+0

你是對的,謝謝pskink。你能發表答案,以便我回答你的答案嗎? – Aximem

回答

1

目標"scrollY"可能是錯誤的(的ofInt最後PARAM),你需要的東西是這樣的:

height_of_content - height_of_container 
+0

感謝pskink,在我的例子中我做了:animScroll = ObjectAnimator.ofInt(scrollView,「scrollY」,linearLayout.getHeight() - scrollView.getHeight());它現在有效! – Aximem

+0

所以現在動畫不會太早......當然要做好準備,如果它<0 ;-) – pskink