當前位置: 首頁>>代碼示例>>Java>>正文


Java View.draw方法代碼示例

本文整理匯總了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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:DragDropTouchListener.java

示例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;
}
 
開發者ID:A-Miracle,項目名稱:QiangHongBao,代碼行數:26,代碼來源:BitmapUtils.java

示例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;
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:37,代碼來源:ArtworkFactory.java

示例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;
}
 
開發者ID:ccrama,項目名稱:Slide-RSS,代碼行數:15,代碼來源:DragSortRecycler.java

示例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;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:20,代碼來源:ImageUtils.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:HeaderRenderer.java

示例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);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:10,代碼來源:ViewUtils.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:ConvertUtils.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:14,代碼來源:BitmapUtil.java

示例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;
}
 
開發者ID:jakebonk,項目名稱:BoardView,代碼行數:13,代碼來源:BoardView.java

示例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;
}
 
開發者ID:Dentacoin,項目名稱:aftercare-app-android,代碼行數:8,代碼來源:DCUtils.java

示例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);
    }
}
 
開發者ID:kyleduo,項目名稱:BlurPopupWindow,代碼行數:32,代碼來源:BlurPopupWindow.java

示例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;
}
 
開發者ID:Loofer,項目名稱:Watermark,代碼行數:8,代碼來源:MarkPresenter.java

示例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);
}
 
開發者ID:ehanoc,項目名稱:xwallet,代碼行數:30,代碼來源:CircleLayout.java

示例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;
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:16,代碼來源:TweetShareFragment.java


注:本文中的android.view.View.draw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。