gpt4 book ai didi

android - 使用相对布局交换两个图像不能正常工作

转载 作者:行者123 更新时间:2023-11-30 03:14:23 25 4
gpt4 key购买 nike

这是基于手指移动的交换代码。我可以交换,但图像不会替换位置。交换后,交换后的图像必须采用新位置,并且必须为此重新设置动画。对于此代码,它会重定向到旧位置并第二次执行动画效果。

if (imageendX > imagestartX && imageendY < imagestartY) {

if (imageendX - imagestartX < 60) {

} else {


TranslateAnimation tr = new TranslateAnimation(0,

90, 0, 0);
tr.setDuration(1000);
// tr.setFillAfter(true);
// tr.setFillEnabled(true);

TranslateAnimation tr2 = new TranslateAnimation(0, -90, 0, 0);
tr2.setDuration(1000);
// tr2.setFillAfter(true);
// tr2.setFillEnabled(true);


currentView.startAnimation(tr);
RightView.startAnimation(tr2);

tr.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {

}

@Override
public void onAnimationRepeat(Animation animation) {

}
});

tr2.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {


}

@Override
public void onAnimationRepeat(Animation animation) {

}
});

}


} else if (imageendY < -10) {


TranslateAnimation tr = new TranslateAnimation(0, 0, 0, -90);
tr.setDuration(1000);
// tr.setFillAfter(true);

TranslateAnimation tr2 = new TranslateAnimation(0, 0, 0,90);
tr2.setDuration(1000);
// tr2.setFillAfter(true);

currentView.startAnimation(tr);
TopView.startAnimation(tr2);

tr2.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {

android.widget.RelativeLayout.LayoutParams pr = (android.widget.RelativeLayout.LayoutParams) TopView
.getLayoutParams();
// pr.topMargin += 90;
pr.topMargin += 90;
TopView.setLayoutParams(pr);

}

@Override
public void onAnimationRepeat(Animation animation) {

}
});
tr.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {

android.widget.RelativeLayout.LayoutParams pr = (android.widget.RelativeLayout.LayoutParams) currentView
.getLayoutParams();
// pr.topMargin += 90;
pr.bottomMargin += 90;
currentView.setLayoutParams(pr);

}

@Override
public void onAnimationRepeat(Animation animation) {

}
});
} else if (imageendY > imagestartY && imageendX < imagestartX) {

if (imageendY - imagestartY < 60) {

} else {



TranslateAnimation tr = new TranslateAnimation(0, 0, 0, RM);
tr.setDuration(1000);
// tr.setFillAfter(true);

TranslateAnimation tr2 = new TranslateAnimation(0, 0, 0, -RM);
tr2.setDuration(1000);
// tr2.setFillAfter(true);

currentView.startAnimation(tr);
BottomView.startAnimation(tr2);

tr2.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {


}

@Override
public void onAnimationRepeat(Animation animation) {

}
});
tr.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {


}

@Override
public void onAnimationRepeat(Animation animation) {

}
});
}

} else if (imagestartX >= imageendX) {
if (imagestartX - imageendX < 90) {
} else {
System.out.println("right to left");
TranslateAnimation tr = new TranslateAnimation(0, RM, 0, 0);
tr.setDuration(1000);
tr.setFillAfter(true);

TranslateAnimation tr2 = new TranslateAnimation(0, -RM, 0, 0);
tr2.setDuration(1000);
tr2.setFillAfter(true);

LeftView.startAnimation(tr);
currentView.startAnimation(tr2);

tr2.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {

}

@Override
public void onAnimationRepeat(Animation animation) {

}
});
tr.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {

}

@Override
public void onAnimationRepeat(Animation animation) {

}
});


}
// }
}

最佳答案

使用 View Animation动画后 View 将处于原始位置,因此根据您的要求使用 Property Animation View 将在动画之后处于动画位置,但唯一的缺点是 API 11 支持属性动画

没问题...使用 NineOldAndroids克服这个问题..

带有两个 ImageView 的示例代码

imageOne 和 imageTwo 之间的动画

ObjectAnimator imageOneAnimator = ObjectAnimator.ofFloat(
imageOne, "X", imageOne.getX(), imageTwo.getX());
ObjectAnimator imageTwoAnimator = ObjectAnimator.ofFloat(
imageTwo, "X", imageTwo.getX(), imageOne.getX());
imageOneAnimator.setDuration(1000);
imageTwoAnimator.setDuration(1000);
AnimatorSet set = new AnimatorSet();
set.playTogether(imageOneAnimator, imageTwoAnimator);
set.start();

imageThree 和 imageOne 之间的动画

ObjectAnimator imageOneYAnimator = ObjectAnimator.ofFloat(
imageOne, "Y", imageOne.getY(), imageThree.getY());
ObjectAnimator imageThreeYAnimator = ObjectAnimator.ofFloat(
imageThree, "Y", imageThree.getY(), imageOne.getY());
imageOneYAnimator.setDuration(1000);
imageThreeYAnimator.setDuration(1000);
AnimatorSet setY = new AnimatorSet();
setY.setStartDelay(1000);
setY.playTogether(imageOneYAnimator, imageThreeYAnimator);
setY.start();

您可以根据您的计算在您的触摸监听器中启动动画

关于android - 使用相对布局交换两个图像不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20396921/

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