下記のようなアニメーションをたくさんのImmageViewに設定したいです。
ImageView一つ一つに対して同じコードを書くしかないのでしょうか?
簡潔に書く方法があれば教えていただきたいです。
int randomAnim; float fromX; float toX; float fromY; float toY; public void anim1 (){ Random random = new Random(); randomAnim = random.nextInt(4); if (randomAnim == 0){ fromX = fromX + 10; toX = fromX + 10; ImageView image1 = (ImageView) findViewById(R.id.image1); ObjectAnimator animator = ObjectAnimator.ofFloat(image1, "translationX",fromX ,toX); animator.setDuration(100); animator.start(); }else if (randomAnim == 1){ fromX = fromX - 10; toX = fromX - 10; ImageView image1 = (ImageView) findViewById(R.id.image1); ObjectAnimator animator = ObjectAnimator.ofFloat(image1, "translationX",fromX ,toX); animator.setDuration(100); animator.start(); }else if (randomAnim == 2){ fromY = fromY + 10; toY = fromY + 10; ImageView image1 = (ImageView) findViewById(R.id.image1); ObjectAnimator animator = ObjectAnimator.ofFloat(image1, "translationY",fromY ,toY); animator.setDuration(100); animator.start(); }else if (randomAnim == 3){ fromY = fromY - 10; toY = fromY - 10; ImageView image1 = (ImageView) findViewById(R.id.image1); ObjectAnimator animator = ObjectAnimator.ofFloat(image1, "translationY",fromY ,toY); animator.setDuration(100); animator.start(); } } コード
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/20 12:19
2016/09/20 12:24
2016/09/20 12:44
2016/09/20 12:53
2016/09/20 14:02
2016/09/20 14:07
2016/09/20 14:51
2016/09/21 00:25 編集
2016/09/21 07:25