android - Android studio 两边不停的动图
问题描述
我有一个图像,它是一只蜜蜂。我想添加一个动画,使蜜蜂看起来像是在指定区域内随机上下飞行。蜜蜂只能paddingTop="200dp"
飞到paddingTop="370dp"
. 当它到达屏幕左侧时,它应该飞回屏幕右侧。它应该从两侧不停地移动。但是,我只能让它在指定的时间段内飞行或水平移动。
<ImageView
android:id="@+id/bee"
android:paddingTop="200dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/beeFaceRight" />
Main.java 中的代码
ObjectAnimator animation;
ImageView bee;
protected void onCreate(Bundle savedInstanceState) {
bee = (ImageView) findViewById(R.id.bee);
animation = ObjectAnimator.ofFloat(bee, "translationX", 100f);
animation.setDuration(2000);
animation.start();
}
我试过这个,但它不起作用。
ObjectAnimator objectX;
ObjectAnimator objectY;
AnimatorSet animatorXY;
objectX = ObjectAnimator.offFloat(bee, "translationX", 0);
objectY = ObjectAnimator.offFloat(bee, "translationY", 200);
animatorXY.playTogether(objectX, objectY);
animatorXY.setDuration(500);
animatorXY.start();
解决方案
推荐阅读
- java - Spring:作用域字段
- javascript - 为什么我的 json 返回 false?
- plotly - jupyterlab/plotly-extension 不会安装
- git - 如何在不克隆容器 git repo 的情况下获取 git 子模块的 git SHA1
- tensorflow - 如何知道从 Graph 中的张量名称列表中选择哪个张量?
- apache - 控制 HDFS 复制、映射器编号和减速器识别
- html - Accordion Dropdown 没有正确设置动画
- tensorflow - 在 Tensorflow Eager Execution 中迭代时内存持续增加
- jquery - vue中如何选择codemirror实例
- vba - 向 Dictionary .VBA 添加多个值