3
我有多個可選擇的視圖。當他們中的一個被選中時,我希望我的新視圖首先定位到與所選位置相同的位置,並將其移動到屏幕頂部。我怎樣才能做到這一點?所選項目的位置不同。將動畫從位置Y翻譯到屏幕頂部
// Selected item
int[] location = new int[2];
item.getLocationOnScreen(location);
int positionY = location[1];
// Move the view I want to move to the position of selected item
viewToMove.setTranslationY(positionY);
// Create and start animation
Animation slideUp = new TranslateAnimation(viewToMove.getTranslationX(), viewToMove.getTranslationX(), positionY, -positionY);
slideUp.setDuration(1000);
slideUp.setFillEnabled(true);
slideUp.setFillAfter(true);
viewToMove.startAnimation(slideUp);