2017-09-06 9 views
0

私はリスナーを持っていて、アニメーションでフォーカスのあるアイテムを少し大きくしています。焦点を当てた項目がクリックされたときに、それが実際に正常に戻っカスタムアニメーショントリガーを2回

fun customFunction(): Unit = with(itemView) { 
    val anim : Animation = AnimationUtils.loadAnimation(itemView.context, R.anim.scale_out) 
    itemView.startAnimation(anim) 
    anim.fillAfter = true 
} 

問題の大きさを変更することは、このリスナー私も作られたカスタム機能のほかに

private fun focus() { 
    itemView?.setOnFocusChangeListener { _, hasFocus -> 
     if (hasFocus) { 
      val anim : Animation = AnimationUtils.loadAnimation(itemView.context, R.anim.scale_in) 
      itemView.startAnimation(anim) 
      anim.fillAfter = true 
     } else { 
      val anim : Animation = AnimationUtils.loadAnimation(itemView.context, R.anim.scale_out) 
      itemView.startAnimation(anim) 
      anim.fillAfter = true 
     } 
    } 
} 

、:focus()customFunction()機能は大丈夫働きます。問題は、フォーカスされた要素(customFunction()トリガ)でEnterキーを押すと要素がノーマルにサイズ変更されることです。これは問題ありません。しかし、私が他の要素に移動する瞬間、前のものは2倍のスケールになります。いくつかの項目をクリックしてcustomFunction()をトリガーした場合、私はonFocusListenerを変更して2回スケールアウトしないでください。どんなアイデアも歓迎されます。

答えて

0

私はあなたの質問を右理解していれば、あなたは試してみて可能性があります。これは動作しませんあなたのcustomFunction()

+0

itemView. setOnFocusChangeListener(null); JoshuaMad