我如何在Kotlin中禁用onTouch

问题描述 投票:0回答:1

我有一个片段class FlipFragment : Fragment(),其中包括CircleShape。当我按下CircleShape时,我调用的方法用一些动画来改变它的资源。我需要这样做,当动画工作时 - onTouch被禁用。我怎么能这样做?

class FlipFragment : Fragment() {
  private var layout = R.layout.view_flip
  private lateinit var CircleShape: ImageView


  override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
      savedInstanceState: Bundle?): View? {
    var view: View = inflater!!.inflate(layout, container, false)
    CircleShape = view.findViewById<ImageView>(R.id.fShapeView)
    Log.i("TAG", CircleShape.isClickable.toString())
    CircleShape.setOnClickLiastener { mechanics() }

    return view
  }
   private fun mechanics() {
    var mechanics = Mechanics(context, this.CircleShape, R.drawable.front_circle,
        R.drawable.back_circle,
        fCircleShapeView)
    mechanics.animation()   ///when this method is working - onTouch should be disable
    mechanics.random()

  }
android kotlin fragment ontouchlistener ontouchevent
1个回答
0
投票

尝试将侦听器添加为AnimationListener。例:

Mechanics.addAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {
        yourView.setEnabled(false);
    }

    @Override
    public void onAnimationEnd(Animation animation) {
        yourView.setEnabled(true);
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
})
© www.soinside.com 2019 - 2024. All rights reserved.