我想制作一个android
用户界面,允许用户移动添加components
/widgets
通过选择它们然后拖动它们来在屏幕上移动。
使用标准的 android api 可以吗?
是的。这取决于您想要实现的目标。
可以办到using标准 API,但此功能不是part of标准 API。也就是说,没有widget.DragOverHere()
方法,除非你自己写一个。
也就是说,做起来不会太复杂。至少,您需要编写 View 的自定义子类并实现两个方法:onDraw(Canvas c)
and onTouch(MotionEvent e)
。粗略的草图:
class MyView extends View {
int x, y; //the x-y coordinates of the icon (top-left corner)
Bitmap bitmap; //the icon you are dragging around
onDraw(Canvas c) {
canvas.drawBitmap(x, y, bitmap);
}
onTouch(MotionEvent e) {
switch(e.getAction()) {
case MotionEvent.ACTION_DOWN:
//maybe use a different bitmap to indicate 'selected'
break;
case MotionEvent.ACTION_MOVE:
x = (int)e.getX();
y = (int)e.getY();
break;
case MotionEvent.ACTION_UP:
//switch back to 'unselected' bitmap
break;
}
invalidate(); //redraw the view
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)