【问题标题】:How I can do disable onTouch in Kotlin如何在 Kotlin 中禁用 onTouch
【发布时间】:2017-12-17 11:18:03
【问题描述】:

我有一个片段class FlipFragment : Fragment() 其中包括圆形。当我按下 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 touch-event


    【解决方案1】:

    尝试添加一个监听器作为 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) {
    
        }
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-28
      • 1970-01-01
      • 1970-01-01
      • 2019-05-04
      • 1970-01-01
      相关资源
      最近更新 更多