ViewTreeObserver vto = container.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override public void onGlobalLayout() {
container.getViewTreeObserver() .removeGlobalOnLayoutListener(this);
width = container.getWidth();
heigh = container.getHeight();
int[] xy = new int[2];
container.getLocationOnScreen(xy);
x = xy[0];
y = xy[1];
} });
/**
* 根据view 返回drawable 对象
* @param view
* @return
*/
public Drawable getDrawable(View view){
int w = screenWidth /2;
int h = screenHeight /2;
Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
// c.translate(-view.getScrollX(), -view.getScrollY());
view.draw(c);
view.setDrawingCacheEnabled(true);
Bitmap viewBmp = b.copy(Bitmap.Config.ARGB_8888, true);
view.destroyDrawingCache();
return new BitmapDrawable(this.getResources(), viewBmp);
// return new BitmapDrawable(viewBmp);
}