android – 将动画从位置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);

解决方法:

随着ViewPropertyAnimator很容易:

viewToMove.animate().translationX(...).translationY(0).setDuration(1000); 

translationY(0)是Y轴的顶部,并且
在translationX(…)处,您可以填写希望视图在X轴上移动到的坐标.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...