Java 如何使用动画从右向左连续移动视图?

Java 如何使用动画从右向左连续移动视图?,java,android,animation,android-popupwindow,Java,Android,Animation,Android Popupwindow,我想显示一个导航指南,因为我正在使用弹出窗口,其中我有一个手部图像,应该从窗口的右向左移动。它应该从右开始,再向左,从右向左滑动 我正在使用一个视图寻呼机,所以我想通过显示一个使用动画的指南来进行指导 我试过了 ImageView imageViewSwipeHand = popupView.findViewById(R.id.imageView_swipe_hand); Animation RightSwipe = AnimationUtils.loa

我想显示一个导航指南,因为我正在使用弹出窗口,其中我有一个手部图像,应该从窗口的右向左移动。它应该从右开始,再向左,从右向左滑动

我正在使用一个视图寻呼机,所以我想通过显示一个使用动画的指南来进行指导

我试过了

    ImageView imageViewSwipeHand =
            popupView.findViewById(R.id.imageView_swipe_hand);

    Animation RightSwipe = AnimationUtils.loadAnimation(
            context,
            R.anim.swipe_right_to_left
    );

    RightSwipe.setRepeatMode(Animation.RESTART);


    RightSwipe.setInterpolator(new LinearInterpolator());
    RightSwipe.setRepeatCount(Animation.INFINITE);

    imageViewSwipeHand.startAnimation(RightSwipe);
它正在从其位置向右移动,主屏幕将消失一秒钟,然后再次在指定位置停止

动画从右到左

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android = "http://schemas.android.com/apk/res/android"
     android:shareInterpolator = "false">
    <translate
        android:duration = "700"
        android:fromXDelta = "0%"
        android:fromYDelta = "0%"
        android:toXDelta = "100%"
        android:toYDelta = "0%" />
</set>

请帮我做同样的事情。谢谢您。

您可以尝试此设置,而不是XML动画设置

        Animation RightSwipe = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0f, Animation.RELATIVE_TO_PARENT, 0f, Animation.RELATIVE_TO_PARENT, 0f);
        RightSwipe.setDuration(1000);
        RightSwipe.setFillAfter(true);
        RightSwipe.setRepeatCount(Animation.INFINITE);

太好了,它起作用了。。现在我只想把它放在窗户中央。现在它从窗口的最右边移动到最左边。我可以这样设置吗?您应该将值从X改为0.5f,而不是1.0f,它将从中心向左移动
    public void showPopupWindow(final View view, AppCompatActivity context) {

        //Create a View object yourself through inflater
        LayoutInflater inflater = (LayoutInflater) view.getContext()
                .getSystemService(view.getContext().LAYOUT_INFLATER_SERVICE);
        View popupView = inflater.inflate(R.layout.instruction_layout, null);


        //Make Inactive Items Outside Of PopupWindow
        boolean focusable = true;

        PopupWindow popupWindow = new PopupWindow(
                popupView,
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT
        );

        popupWindow.showAtLocation(view, Gravity.CENTER,
                0, 0
        );

        popupWindow.setOutsideTouchable(true);
        popupWindow.setFocusable(true);

        ImageView imageViewSwipeHand =
                popupView.findViewById(R.id.imageView_swipe_hand);

        Animation RightSwipe = AnimationUtils.loadAnimation(
                context,
                R.anim.swipe_right_to_left
        );

        RightSwipe.setRepeatMode(Animation.RESTART);

        RightSwipe.setInterpolator(new LinearInterpolator());
        RightSwipe.setRepeatCount(Animation.INFINITE);

        imageViewSwipeHand.startAnimation(RightSwipe);

        Button button = popupView.findViewById(R.id.button_got_it);

        button.setOnClickListener(new View.OnClickListener() {
            @Override public void onClick(View v) {

                popupWindow.dismiss();

            }
        });

    }
        Animation RightSwipe = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0f, Animation.RELATIVE_TO_PARENT, 0f, Animation.RELATIVE_TO_PARENT, 0f);
        RightSwipe.setDuration(1000);
        RightSwipe.setFillAfter(true);
        RightSwipe.setRepeatCount(Animation.INFINITE);