-1
我想要在佈局中移動視圖,並使用API Level 11(startDrag,將View.DragShadowBuilder覆蓋爲shadowView)實現該視圖,但遇到問題時,無法獲取拖放視圖時的實際座標。在拖放時獲得DragShadow座標?
我試過使用getView.getX()
,但是當drop view時它的值不爲零。
如何在時間下降視圖中獲得座標?
public SimeDragShadowView(View view, Context context) {
super(view);
shadow = new ColorDrawable(Color.BLUE);
mDragShadowView = getView();
mInitX = (int) view.getX();
mInitY = SimeTabContainer.mDownViewInitY;
if(DEBUG){
Log.d(TAG, " shadow button width is .."+getView().getWidth() +"... height is .."+getView().getHeight());
}
}
@Override
public void onProvideShadowMetrics(Point size, Point touch) {
// Defines local variables
if(DEBUG){
Log.d(TAG, " onProvideShadowMetrics()");
}
int width, height;
width = getView().getWidth();
height = getView().getHeight();
shadow.setBounds(mInitX-10, mInitY-10, mInitX + width, mInitY + height);
size.set(width, height);
touch.set(width/2, height/2);
}
@Override
public void onDrawShadow(Canvas canvas) {
// Draws the ColorDrawable in the Canvas passed in from the system.
shadow.draw(canvas);
getView().draw(canvas);
if(DEBUG){
Log.d(TAG, " getView()... x cor is .."+getView().getX());
}
}