Vì vậy, nó chỉ ra rằng điều này là thẳng tiến hơn nhiều so với tôi tưởng tượng.
Tôi đã tạo ra toàn màn hình RelativeLayout mà tôi chỉ hiển thị trong khi hoạt ảnh đang diễn ra.
tôi nhận được vị trí bắt đầu của nút chôn tôi như thế này (nó buồn cười để nhìn thấy những cơ chế C phong cách mã hóa trong Java, họ đang khá hiếm những ngày này:
int fromLoc[] = new int[2];
v.getLocationOnScreen(fromLoc);
float startX = fromLoc[0];
float startY = fromLoc[1];
Vì vậy, bây giờ tôi phải bắt đầu của tôi điểm.
điểm cuối cùng của tôi là hoàn toàn phối hợp trên màn hình, bạn có thể gán rằng tuy nhiên bạn muốn
Sau đó, tôi thực hiện một ít lớp helper Animations cho phép tôi vượt qua trong tất cả các tọa độ, gọi lại, và thời lượng của hoạt ảnh
public class Animations {
public Animation fromAtoB(float fromX, float fromY, float toX, float toY, AnimationListener l, int speed){
Animation fromAtoB = new TranslateAnimation(
Animation.ABSOLUTE, //from xType
fromX,
Animation.ABSOLUTE, //to xType
toX,
Animation.ABSOLUTE, //from yType
fromY,
Animation.ABSOLUTE, //to yType
toY
);
fromAtoB.setDuration(speed);
fromAtoB.setInterpolator(new AnticipateOvershootInterpolator(1.0f));
if(l != null)
fromAtoB.setAnimationListener(l);
return fromAtoB;
}
}
và chúng ta cần một người biết lắng nghe để cho chúng tôi biết khi nào hình ảnh động được thực hiện để xóa nó
AnimationListener animL = new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
//this is just a method to delete the ImageView and hide the animation Layout until we need it again.
clearAnimation();
}
};
Và cuối cùng chúng ta ném nó tất cả cùng nhau và nhấn GO
int fromLoc[] = new int[2];
v.getLocationOnScreen(fromLoc);
float startX = fromLoc[0];
float startY = fromLoc[1];
RelativeLayout rl = ((RelativeLayout)findViewById(R.id.sticker_animation_layout));
ImageView sticker = new ImageView(this);
int stickerId = getStickerIdFromButton(v);
if(stickerId == 0){
stickerAnimationPlaying = false;
return;
}
float destX = 200.0f;//arbitrary place on screen
float destY = 200.0f;//arbitrary place on screen
sticker.setBackgroundResource(stickerId);
sticker.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
rl.addView(sticker);
Animations anim = new Animations();
Animation a = anim.fromAtoB(startX, startY, destX, destY, animL,750);
sticker.setAnimation(a);
a.startNow();
ok, tôi đã figured it out bản thân mình, nếu không có ai chuông với một câu trả lời, tôi sẽ gửi nó vào ngày mai, cho những người khác tham khảo. –
Bạn có hướng dẫn về điều này không? – ManishSB