作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想为从屏幕中央开始的 ImageView 设置动画,并将其向上移动到屏幕顶部下方 10 像素处。如何在代码中实现这一点?
我目前正在做的是,我正在获取另一个图像上的屏幕坐标,并将这个动画图像稍微放在它上面,但是在高密度的大屏幕上,它不会保持不变距离,所以我想将它从顶部移动 10px。
我怎样才能做到这一点?
这是我的代码:
//calculate where to put the logo in y-axis depending on screen size
int coords[] = {0,0};
logoImageFixed.getLocationOnScreen(coords);
int y = coords[1];
int imgFixedHeight = logoImageFixed.getHeight();
Log.d("daim","height: "+imgFixedHeight);
float pointY = -(y + 3*imgFixedHeight);
Animation a = new LogoAnimation(0.0f, 0.0f, 0.0f, pointY);
a.setFillAfter(true);
a.setDuration(600);
a.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
logoAnimated = true;
}
});
logoImage.startAnimation(a);
最佳答案
好吧,我认为你在正确的道路上
int[] coords = {0,0};
logoImage.getLocationOnScreen(coords);
int y = coords[1];
//to top of screen
TranslateAnimation toTop = new TranslateAnimation(0, 0, 0, -y);
toTop.setDuration(700);
toTop.setFillAfter(true);
logoImage.startAnimation(toTop);
但是如果你想添加 padding 10 像素你需要这样做
//padding 10 pixels from top
TranslateAnimation toTop = new TranslateAnimation(0, 0, 0, ((-y) - 10));
toTop.setDuration(700);
toTop.setFillAfter(true);
logoImage.startAnimation(toTop);
关于Android - TranslateAnimation 从中到上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11136050/
这个问题在这里已经有了答案: Is a moved-from vector always empty? (4 个答案) 关闭 4 年前。 从 std::vector move 数据后,它的容量是否必
我是一名优秀的程序员,十分优秀!