gpt4 book ai didi

Android - TranslateAnimation 从中到上

转载 作者:搜寻专家 更新时间:2023-11-01 08:09:36 26 4
gpt4 key购买 nike

我想为从屏幕中央开始的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com