gpt4 book ai didi

java - 动画无法正常工作?

转载 作者:太空宇宙 更新时间:2023-11-04 15:23:00 24 4
gpt4 key购买 nike

我想通过翻译动画将图像按钮翻译到另一个位置(到另一个图像按钮的位置)。他们两个的职位我都有。我拥有的动画方法都是使用相对位置变化,但我对绝对平移感兴趣。 Android 中有什么方法可以做到这一点吗?

 public void startAnimationFindChant(View view) {
int[] locationSource = new int[2];
int[] locationDestination = new int[2];
view.geLocationOnScreen(locationSource);
Log.d("locationSource",locationSource[0]+" "+locationSource[1]);
ImageButton findachant1 = (ImageButton) findViewById(R.id.findachanticon1);

findachant1.getLocationOnScreen(locationDestination);
Log.d("locationDestination",locationDestination[0]+" "+locationDestination[1]);

TranslateAnimation animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
Animation.ABSOLUTE, locationSource[1], Animation.ABSOLUTE,
locationDestination[1]);
animation.setFillAfter(true);
view.startAnimation(animation);
}

最佳答案

public void doSlideUp(View view) {
LinearLayout myView = (LinearLayout) findViewById(R.id.content_area);
Animation slideUp = setLayoutAnim_slideup();
myView.startAnimation(slideUp);

}

public void doSlideDown(View view) {
RelativeLayout myView = (RelativeLayout) findViewById(R.id.content_area1);
Animation slideDown = setLayoutAnim_slidedown();
myView.startAnimation(slideDown);
}

public Animation setLayoutAnim_slidedown() {

AnimationSet set = new AnimationSet(true);

Animation animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, -1.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
animation.setDuration(2000);
animation.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
}

@Override
public void onAnimationRepeat(Animation animation) {
}

@Override
public void onAnimationEnd(Animation animation) {

}
});
set.addAnimation(animation);

LayoutAnimationController controller = new LayoutAnimationController(
set, 0.25f);

return animation;
}

public Animation setLayoutAnim_slideup() {

AnimationSet set = new AnimationSet(true);

Animation animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -1.0f);
animation.setDuration(2000);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationRepeat(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {




}
});
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(
set, 0.25f);
return animation;
}

尝试此操作并根据需要将动画 x 轴的值更改为 y 轴。

关于java - 动画无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20210999/

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