在Android上使用手指拖动VideoView

时间:2018-05-21 13:34:09

标签: java android android-videoview

我尝试使用VideoView跟随手指。我编写了相同的代码,可以与ImageView一起使用,但它不适用于VideoView。

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {

     final int Y = (int) motionEvent.getRawY();
     FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
     switch (motionEvent.getAction()) {
         case MotionEvent.ACTION_DOWN: // A pressed gesture has started
             y1 = view.getY();
             yDelta = Y - layoutParams.topMargin;
             originalTopMargin = layoutParams.topMargin;
             break;

         case MotionEvent.ACTION_UP:
             layoutParams.topMargin = originalTopMargin;
             layoutParams.bottomMargin = 0;
             view.setLayoutParams(layoutParams);
             break;

         case MotionEvent.ACTION_MOVE:
             layoutParams.topMargin = Y - yDelta;
             layoutParams.bottomMargin = -(Y - yDelta);
             float y2 = view.getY();
             float deY = y2 - y1;
             if(Math.abs(deY) > MIN_DISTANCE){
                 finish();
             }
             view.setLayoutParams(layoutParams);
             break;
    }
    return false;
}

0 个答案:

没有答案