質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

0回答

203閲覧

タップするごとにアニメーションを発生させながら、十回タップ後に画像変更もするには?

maturika2109

総合スコア0

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2022/06/23 17:46

実現したいこと

画面タップ(そのたびに発生するアニメーション)を十回行った瞬間、別の画像へ変更を行いたい。
以下のコードで十回タップすると画像変更は行われるが、なぜかアニメーションが発生しません。

kotlin

1class MainActivity : AppCompatActivity() { 2 override fun onCreate(savedInstanceState: Bundle?) { 3 super.onCreate(savedInstanceState) 4 setContentView(R.layout.tama) 5 6 7 fun yure(yurayura: View) {     ←アニメーションのコードはこっから 8 9 val animatorList: MutableList<Animator> = ArrayList() 10 11 animatorList.add(ObjectAnimator.ofFloat(yurayura, "translationX", 0f, -100f).setDuration(10)) 12 animatorList.add(ObjectAnimator.ofFloat(yurayura, "translationX", -100f, 70f).setDuration(30)) 13 animatorList.add(ObjectAnimator.ofFloat(yurayura, "translationX", 70f, -50f).setDuration(60)) 14 animatorList.add(ObjectAnimator.ofFloat(yurayura, "translationX", -50f, 40f).setDuration(100)) 15 animatorList.add(ObjectAnimator.ofFloat(yurayura, "translationX", 40f, -30f).setDuration(150)) 16 animatorList.add(ObjectAnimator.ofFloat(yurayura, "translationX", -30f, 0f).setDuration(210)) 17 18 val set = AnimatorSet() 19 set.playSequentially(animatorList) 20 set.start() 21 } 22 yurayura.setOnClickListener { 23 val v: View = yurayura 24 yure(v) 25 26 }アニメーションのコードはここまで(発生しない……) 27 28 var taxtuti = 0←ここから十回タップで画像変更コード 29 yurayura.setOnClickListener{ 30 taxtuti++ 31 when(taxtuti){ 32 10 -> yurayura.setImageResource(R.drawable.pann) 33 } 34 } 35 } 36}    ここまで

tama.xml

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 android:background="#F6F5F5" 8 tools:context=".MainActivity" > 9 10 <ImageView 11 android:id="@+id/yurayura" 12 android:layout_width="wrap_content" 13 android:layout_height="wrap_content" 14 android:background="@color/white" 15 android:backgroundTint="@color/white" 16 app:layout_constraintBottom_toBottomOf="parent" 17 app:srcCompat="@drawable/siroitamago" 18 tools:layout_editor_absoluteX="0dp" /> 19</androidx.constraintlayout.widget.ConstraintLayout>

activity_subtamago.xml

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".subtamago"> 8 9 <ImageView 10 android:id="@+id/medama" 11 android:layout_width="wrap_content" 12 android:layout_height="wrap_content" 13 app:srcCompat="@drawable/pann" 14 tools:layout_editor_absoluteX="0dp" 15 tools:layout_editor_absoluteY="0dp" /> 16</androidx.constraintlayout.widget.ConstraintLayout>

試したこと

どうにか自力でここまでコードを書き、十回タップで画像変更は起きるものの、タップするごとに起きるはずのアニメーションが発生しません。
あと一息なのですが、どこを直せば見当もつかないんです。
どうか、よろしくお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hoshi-takanori

2022/06/25 14:47

アニメーションと画面遷移を分けて setOnClickListener してるからでは。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問