本文整理汇总了Java中android.view.View.draw方法的典型用法代码示例。如果您正苦于以下问题:Java View.draw方法的具体用法?Java View.draw怎么用?Java View.draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyViewAsImage
import android.view.View; //导入方法依赖的package包/类
private ImageView copyViewAsImage(View v) {
//Clear ripple effect to not get into screenshot,
// need something more clever here
if (v instanceof FrameLayout) {
FrameLayout frameLayout = (FrameLayout) v;
Drawable foreground = frameLayout.getForeground();
if (foreground != null) foreground.setVisible(false, false);
} else {
if (v.getBackground() != null) v.getBackground().setVisible(false, false);
}
Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
v.draw(canvas);
//Drag highlight, usually border
if (dragHighlight != null) {
dragHighlight.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
dragHighlight.draw(canvas);
}
ImageView imageView = new ImageView(recyclerView.getContext());
imageView.setImageBitmap(bitmap);
return imageView;
}
示例2: createBitmapFromView
import android.view.View; //导入方法依赖的package包/类
/**
* 从视图创建位图
* @param view
* @return
*/
public static Bitmap createBitmapFromView(View view) {
if (view instanceof ImageView) {
Drawable drawable = ((ImageView) view).getDrawable();
if (drawable != null && drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
}
view.clearFocus();
Bitmap bitmap = createBitmapSafely(view.getWidth(),
view.getHeight(), Bitmap.Config.ARGB_8888, 1);
if (bitmap != null) {
synchronized (sCanvas) {
Canvas canvas = sCanvas;
canvas.setBitmap(bitmap);
view.draw(canvas);
canvas.setBitmap(null);
}
}
return bitmap;
}
示例3: createViewBitmap
import android.view.View; //导入方法依赖的package包/类
public Bitmap createViewBitmap(View view, Layout textLayout, int bitmapWidth, int bitmapHeight, int vertical_align) {
final int actualBitmapWidth = getPowerOfTwo(bitmapWidth);
final int actualBitmapHeight = getPowerOfTwo(bitmapHeight);
Bitmap destBitmap = Bitmap.createBitmap( actualBitmapWidth, actualBitmapHeight, Bitmap.Config.ARGB_8888 );
destBitmap.eraseColor(Color.TRANSPARENT);
synchronized (mCanvas) {
mCanvas.setBitmap(destBitmap);
mCanvas.save();
// Center the bitmap horizontally inside the "powerOfTwo" texture bitmap
mCanvas.translate((actualBitmapWidth - bitmapWidth) / 2, 0);
// Align vertically depending of the argument
switch (vertical_align) {
case ALIGN_BOTTOM:
mCanvas.translate(0,actualBitmapHeight - bitmapHeight);
break;
case ALIGN_TOP:
break;
case ALIGN_CENTER:
default:
mCanvas.translate(0, (actualBitmapHeight - bitmapHeight) / 2);
}
view.draw(mCanvas);
if (textLayout != null) {
// Draw the text using the TextLayout if one is provided
mCanvas.translate(0, (actualBitmapHeight - bitmapHeight) / 2);
textLayout.draw(mCanvas);
}
mCanvas.restore();
}
return destBitmap;
}
示例4: createFloatingBitmap
import android.view.View; //导入方法依赖的package包/类
private BitmapDrawable createFloatingBitmap(View v) {
floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
floatingItemBounds = new Rect(floatingItemStatingBounds);
Bitmap bitmap = Bitmap.createBitmap(floatingItemStatingBounds.width(),
floatingItemStatingBounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
v.draw(canvas);
BitmapDrawable retDrawable = new BitmapDrawable(v.getResources(), bitmap);
retDrawable.setBounds(floatingItemBounds);
return retDrawable;
}
示例5: view2Bitmap
import android.view.View; //导入方法依赖的package包/类
/**
* view转Bitmap
*
* @param view 视图
* @return bitmap
*/
public static Bitmap view2Bitmap(View view) {
if (view == null) return null;
Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(ret);
Drawable bgDrawable = view.getBackground();
if (bgDrawable != null) {
bgDrawable.draw(canvas);
} else {
canvas.drawColor(Color.WHITE);
}
view.draw(canvas);
return ret;
}
示例6: drawHeader
import android.view.View; //导入方法依赖的package包/类
/**
* Draws a header to a canvas, offsetting by some x and y amount
*
* @param recyclerView the parent recycler view for drawing the header into
* @param canvas the canvas on which to draw the header
* @param header the view to draw as the header
* @param offset a Rect used to define the x/y offset of the header. Specify x/y offset by setting
* the {@link Rect#left} and {@link Rect#top} properties, respectively.
*/
public void drawHeader(RecyclerView recyclerView, Canvas canvas, View header, Rect offset) {
canvas.save();
if (recyclerView.getLayoutManager().getClipToPadding()) {
// Clip drawing of headers to the padding of the RecyclerView. Avoids drawing in the padding
Rect clipRect = getClipRectForHeader(recyclerView, header);
canvas.clipRect(clipRect);
}
canvas.translate(offset.left, offset.top);
header.draw(canvas);
canvas.restore();
}
示例7: captureBitmap
import android.view.View; //导入方法依赖的package包/类
/**
* Captures a bitmap of a View and draws it to a Canvas.
*/
public static void captureBitmap(View view, Canvas canvas) {
// Invalidate all the descendants of view, before calling view.draw(). Otherwise, some of
// the descendant views may optimize away their drawing. http://crbug.com/415251
recursiveInvalidate(view);
view.draw(canvas);
}
示例8: view2Bitmap
import android.view.View; //导入方法依赖的package包/类
/**
* view转Bitmap
*
* @param view 视图
* @return bitmap
*/
public static Bitmap view2Bitmap(final View view) {
if (view == null) return null;
Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(ret);
Drawable bgDrawable = view.getBackground();
if (bgDrawable != null) {
bgDrawable.draw(canvas);
} else {
canvas.drawColor(Color.WHITE);
}
view.draw(canvas);
return ret;
}
示例9: loadBitmapFromView
import android.view.View; //导入方法依赖的package包/类
public static Bitmap loadBitmapFromView(View v) {
if (v.getMeasuredHeight() > 0) {
return null;
}
v.measure(MeasureSpec.makeMeasureSpec((int) DensityUtil.getScreenWidth(v.getContext()),
1073741824), MeasureSpec.makeMeasureSpec(0, 0));
Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Config
.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.draw(c);
return b;
}
示例10: getBitmapFromView
import android.view.View; //导入方法依赖的package包/类
private Bitmap getBitmapFromView(View v, float scale){
double radians = 0.0523599f;
double s = Math.abs(Math.sin(radians));
double c = Math.abs(Math.cos(radians));
int width = (int)(v.getHeight()*s + v.getWidth()*c);
int height = (int)(v.getWidth()*s + v.getHeight()*c);
Bitmap bitmap = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.scale(scale,scale);
v.draw(canvas);
return bitmap;
}
示例11: loadBitmapFromView
import android.view.View; //导入方法依赖的package包/类
public static Bitmap loadBitmapFromView(View v) {
Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE);
v.draw(canvas);
return bitmap;
}
示例12: BlurTask
import android.view.View; //导入方法依赖的package包/类
BlurTask(View sourceView, int statusBarHeight, int navigationBarheight, BlurPopupWindow popupWindow, BlurTaskCallback blurTaskCallback) {
mContextRef = new WeakReference<>(sourceView.getContext());
mPopupWindowRef = new WeakReference<>(popupWindow);
mBlurTaskCallback = blurTaskCallback;
int height = sourceView.getHeight() - statusBarHeight - navigationBarheight;
if (height < 0) {
height = sourceView.getHeight();
}
Drawable background = sourceView.getBackground();
mSourceBitmap = Bitmap.createBitmap(sourceView.getWidth(), height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(mSourceBitmap);
int saveCount = 0;
if (statusBarHeight != 0) {
saveCount = canvas.save();
canvas.translate(0, -statusBarHeight);
}
if (popupWindow.getBlurRadius() > 0) {
if (background == null) {
canvas.drawColor(0xffffffff);
}
sourceView.draw(canvas);
}
if (popupWindow.getTintColor() != 0) {
canvas.drawColor(popupWindow.getTintColor());
}
if (statusBarHeight != 0 && saveCount != 0) {
canvas.restoreToCount(saveCount);
}
}
示例13: getBitmapByView
import android.view.View; //导入方法依赖的package包/类
public Bitmap getBitmapByView(View v) {
Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
v.draw(canvas);
return bitmap;
}
示例14: drawChild
import android.view.View; //导入方法依赖的package包/类
private void drawChild(Canvas canvas, View child, LayoutParams lp) {
mSrcCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
mDstCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
mSrcCanvas.save();
int childLeft = child.getLeft();
int childTop = child.getTop();
int childRight = child.getRight();
int childBottom = child.getBottom();
mSrcCanvas.clipRect(childLeft, childTop, childRight, childBottom, Op.REPLACE);
mSrcCanvas.translate(childLeft, childTop);
child.draw(mSrcCanvas);
mSrcCanvas.restore();
mXferPaint.setXfermode(null);
mXferPaint.setColor(Color.BLACK);
float sweepAngle = (lp.endAngle - lp.startAngle) % 361;
mDstCanvas.drawArc(mBounds, lp.startAngle, sweepAngle, true, mXferPaint);
mXferPaint.setXfermode(mXfer);
mDstCanvas.drawBitmap(mSrc, 0f, 0f, mXferPaint);
canvas.drawBitmap(mDst, 0f, 0f, null);
}
示例15: create
import android.view.View; //导入方法依赖的package包/类
private static Bitmap create(View v) {
try {
int w = v.getWidth();
int h = v.getHeight();
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
Canvas c = new Canvas(bmp);
c.drawColor(Color.WHITE);
v.layout(0, 0, w, h);
v.draw(c);
return bmp;
} catch (OutOfMemoryError error) {
error.printStackTrace();
return null;
}
}