android的VideoView怎么实现拖拽我想让Vid
2016-04-03 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
你先继承 VIEW . 然后重写以下函数 就可以实现拖拽的功能了.
至于要显示图片,你可以直接在 onDraw里面描绘出来就好
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
final int X = (int) event.getRawX();
final int Y = (int) event.getRawY();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) getLayoutParams();
_xDelta = X - lParams.leftMargin;
_yDelta = Y - lParams.topMargin;
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
layoutParams.leftMargin = X - _xDelta;
layoutParams.topMargin = Y - _yDelta;
//layoutParams.rightMargin = -250;
//layoutParams.bottomMargin = -250;
HanoiItem.this.setLayoutParams(layoutParams); //自己继承VIEW的this
break;
}
invalidate();
return true;
}
至于位置,你就可以直接new VIEW 之后直接 用 VIEW.set**实现的啊
至于要显示图片,你可以直接在 onDraw里面描绘出来就好
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
final int X = (int) event.getRawX();
final int Y = (int) event.getRawY();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) getLayoutParams();
_xDelta = X - lParams.leftMargin;
_yDelta = Y - lParams.topMargin;
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
layoutParams.leftMargin = X - _xDelta;
layoutParams.topMargin = Y - _yDelta;
//layoutParams.rightMargin = -250;
//layoutParams.bottomMargin = -250;
HanoiItem.this.setLayoutParams(layoutParams); //自己继承VIEW的this
break;
}
invalidate();
return true;
}
至于位置,你就可以直接new VIEW 之后直接 用 VIEW.set**实现的啊
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询