【问题标题】:MotionLayout with Exoplayer handle touch events not properly带有 Exoplayer 的 MotionLayout 无法正确处理触摸事件
【发布时间】:2021-04-29 05:44:48
【问题描述】:

我在 Motion Layout 中有 OnSwipe 动画和一个 ExoPlayer。但是当 exoplayer 播放时,运动布局动画不起作用。我认为 ExoPlayer 拦截了触摸事件。我该如何解决这个问题?例如 Youtube 应用程序处理滑动和点击事件

【问题讨论】:

    标签: android android-animation android-motionlayout


    【解决方案1】:

    有一种简单的方法可以做到这一点 扩展 MotionLayout 类并覆盖

    onInterceptTouchEvent()

     @Override
        public boolean onInterceptTouchEvent(MotionEvent event) {
            if (onTouchEvent(event)) {
                return false;
            } else {
                return true;
            }
        }
    

    这是将 Childs 触摸事件传递给父级或背景布局的最简单方法。 这将解决您的问题。

    【讨论】:

      【解决方案2】:

      我通过创建自定义播放器视图解决了这个问题。问题是 PlayerView 拦截了触摸事件,所以运动布局没有得到任何触摸事件。通过将 PlayerView.onTouchEvent 的返回值从 true 更改为 false,运动布局可以处理滑动事件。

      internal class CustomExoPlayerView(
          context: Context, attributeSet: AttributeSet? = null
      ) : PlayerView(context, attributeSet) {
      
          @SuppressLint("ClickableViewAccessibility")
          override fun onTouchEvent(event: MotionEvent): Boolean {
              when (event.action) {
                  MotionEvent.ACTION_DOWN -> {
                      showController()
                  }
              }
              return false
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-09
        • 2012-10-26
        相关资源
        最近更新 更多