本文整理了Java中android.widget.TextView.draw()
方法的一些代码示例,展示了TextView.draw()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.draw()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:draw
暂无
代码示例来源:origin: googlemaps/android-maps-utils
@Override
public void draw(Canvas canvas) {
canvas.translate(mOffsetLeft / 2, mOffsetTop / 2);
super.draw(canvas);
}
}
代码示例来源:origin: stackoverflow.com
view.draw(canvas);
canvas.restore();
代码示例来源:origin: ZieIony/Carbon
public void drawInternal(@NonNull Canvas canvas) {
super.draw(canvas);
if (stroke != null)
drawStroke(canvas);
if (rippleDrawable != null && rippleDrawable.getStyle() == RippleDrawable.Style.Over)
rippleDrawable.draw(canvas);
}
代码示例来源:origin: willowtreeapps/Hyperion-Android
canvas.translate(rectPrimary.centerX() - (measurementWidthText.getWidth() / 2),
rectPrimary.top - measurementWidthText.getHeight() - measurementTextOffset);
measurementWidthText.draw(canvas);
canvas.restore();
canvas.translate(rectPrimary.right + measurementTextOffset,
rectPrimary.bottom - (rectPrimary.height() / 2) - (measurementHeightText.getHeight() / 2));
measurementHeightText.draw(canvas);
canvas.restore();
canvas.translate(rectSecondary.centerX() - measurementHeightText.getWidth() / 2,
(rectPrimary.bottom + rectSecondary.top) / 2 - (measurementHeightText.getHeight() / 2));
measurementHeightText.draw(canvas);
canvas.restore();
canvas.translate((rectPrimary.right + rectSecondary.left) / 2 - (measurementWidthText.getWidth() / 2),
rectSecondary.centerY() - measurementWidthText.getHeight() / 2);
measurementWidthText.draw(canvas);
canvas.restore();
canvas.translate(rectSecondary.centerX() - measurementHeightText.getWidth() / 2,
(rectPrimary.top + rectSecondary.bottom) / 2 - (measurementHeightText.getHeight() / 2));
measurementHeightText.draw(canvas);
canvas.restore();
canvas.translate((rectPrimary.left + rectSecondary.right) / 2 - (measurementWidthText.getWidth() / 2),
rectSecondary.centerY() - measurementWidthText.getHeight() / 2);
measurementWidthText.draw(canvas);
canvas.restore();
代码示例来源:origin: wiglenet/wigle-wifi-wardriving
@Override
public void draw(Canvas canvas) {
canvas.translate(mOffsetLeft / 2, mOffsetTop / 2);
super.draw(canvas);
}
}
代码示例来源:origin: stackoverflow.com
TextView textView = new TextView(getContext());
int width = (int) (rect.right - rect.left);
int height = (int) (rect.bottom - rect.top);
textView.layout(0, 0, width, height);
textView.setText(e.getSummary());
Bitmap bitmapText = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvasText = new Canvas(bitmapText);
textView.draw(canvasText);
canvas.drawBitmap(bitmapText, rect.left, rect.top, null);
代码示例来源:origin: czy1121/badgebutton
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
mBadgeDrawable.draw(canvas);
}
代码示例来源:origin: stackoverflow.com
TextView usertext = new TextView(this);
usertext.setText("Hi Hello");
usertext.setTextSize(22);
usertext.setBackgroundColor(Color.TRANSPARENT);
Bitmap testB;
testB = Bitmap.createBitmap(TextLayout.getWidth(), TextLayout.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(testB);
usertext.layout(0, 0, 80, 100);
usertext.draw(c);
// create imageview in layout file and declare here
Imageview iv = (Imageview) findviewByid(your imageview id)
iv.setImageBitmap(testB);
iv.setOnTouchListener(this);
代码示例来源:origin: stackoverflow.com
// ...
PdfDocument.Page page = document.startPage(pageInfo);
TextView textView = new TextView(ctx);
textView.setText("1,2,3");
// here the solution
int left = 0;
int top = 0;
int width = 200;
int height = 200;
textView.layout(0,0,width,height);
canvas.save()
canvas.translate(left,top);
textView.draw(page.getCanvas());
canvas.restore()
代码示例来源:origin: evilbinary/TvWidget
@Override
public void draw(Canvas canvas) {
if (hasFocus()) {
super.getDrawingRect(mRect);
mBound.set(-borderSize + mRect.left, -borderSize + mRect.top, borderSize + mRect.right, borderSize + mRect.bottom);
mBorderDrawable.setBounds(mBound);
canvas.save();
if (mBorderDrawable != null)
mBorderDrawable.draw(canvas);
canvas.restore();
}
super.draw(canvas);
}
代码示例来源:origin: stackoverflow.com
TextView textView = new TextView(getContext());
textView.setText(DetailsActivity.temp_desc);
textView.setMinLines(1);
canvas.translate(0,bitmap.getHeight());
textView.layout(0, 0, 500, 150);
textView.draw(canvas);
代码示例来源:origin: stackoverflow.com
private Bitmap loadBitmap(int width, int height, int index) {
Bitmap txtBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
String text1 = yourPagesStringArray[index];
Canvas c = new Canvas(txtBitmap);
TextView tv = new TextView(getApplicationContext());
tv.setText(text1);
tv.setTextColor(0xa00050ff);
tv.setTextSize(15);
tv.setLinksClickable(true);
tv.setLineSpacing(2, 2);
tv.layout(0, 0, getResources().getDisplayMetrics().widthPixels, getResources().getDisplayMetrics().heightPixels);
tv.draw(c);
c.drawBitmap(txtBitmap, 0, 0, null);
return txtBitmap;
}
代码示例来源:origin: stackoverflow.com
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(80, 100);
tv.setLayoutParams(layoutParams);
tv.setText("testing 1 2 3");
tv.setTextColor(Color.BLACK);
tv.setBackgroundColor(Color.TRANSPARENT);
Bitmap testB;
testB = Bitmap.createBitmap(80, 100, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(testB);
tv.layout(0, 0, 80, 100);
tv.draw(c);
ImageView iv = new ImageView(this);
iv.setLayoutParams(layoutParams);
iv.setBackgroundColor(Color.GRAY);
iv.setImageBitmap(testB);
setContentView(iv);
}
代码示例来源:origin: stackoverflow.com
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(80, 100);
tv.setLayoutParams(layoutParams);
tv.setText("testing 1 2 3");
tv.setTextColor(Color.BLACK);
tv.setBackgroundColor(Color.TRANSPARENT);
Bitmap testB;
testB = Bitmap.createBitmap(80, 100, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(testB);
tv.layout(0, 0, 80, 100);
tv.draw(c);
ImageView iv = (ImageView)findViewById(R.id.menuIcon);
iv.setLayoutParams(layoutParams);
iv.setBackgroundColor(Color.GRAY);
iv.setImageBitmap(testB);
iv.setMaxHeight(80);
iv.setMaxWidth(80);
}
代码示例来源:origin: stackoverflow.com
TextView textV = new TextView(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(128, 128);
textV.setLayoutParams(layoutParams);
textV.setTextColor(Color.WHITE);
textV.setBackgroundColor(Color.TRANSPARENT);
textV.setGravity(Gravity.CENTER);
textV.setText(text);
textV.setDrawingCacheEnabled(true);
Bitmap b = Bitmap.createBitmap( textV.getLayoutParams().width, textV.getLayoutParams().height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
textV.layout(0, 0, textV.getLayoutParams().width, textV.getLayoutParams().height);
textV.draw(c);
textV.setDrawingCacheEnabled(false);
代码示例来源:origin: stackoverflow.com
TextView upTextView = (TextView) getLayoutInflater().inflate(
R.layout.up_text, null);
upTextView.setText("CITIES");
upTextView.measure(0, 0);
upTextView.layout(0, 0, upTextView.getMeasuredWidth(),
upTextView.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(upTextView.getMeasuredWidth(),
upTextView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
upTextView.draw(canvas);
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
代码示例来源:origin: stackoverflow.com
private static Bitmap renderTextIntoBitmap(Context context, Bitmap.Config bitmapConfig, String text, int textColor, int maxTextWidth) {
LayoutInflater inflater = LayoutInflater.from(context);
TextView tv = (TextView) inflater.inflate(R.layout.just_a_textview, null);
tv.setText(text);
tv.setMaxWidth(maxTextWidth);
int widthSpec = View.MeasureSpec.makeMeasureSpec(maxTextWidth, View.MeasureSpec.EXACTLY);
int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
tv.measure(widthSpec, heightSpec);
tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());
tv.setTextColor(textColor);
Bitmap bitmap = Bitmap.createBitmap(tv.getWidth(), tv.getHeight(), bitmapConfig);
Canvas canvas = new Canvas(bitmap);
tv.draw(canvas);
return bitmap;
}
代码示例来源:origin: googlesamples/android-unsplash
private static Bitmap captureTextBitmap(TextView textView) {
Drawable background = textView.getBackground();
textView.setBackground(null);
int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight();
int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom();
if (width == 0 || height == 0) {
return null;
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop());
textView.draw(canvas);
textView.setBackground(background);
return bitmap;
}
代码示例来源:origin: DroidsOnRoids/Workcation
private static Bitmap captureTextBitmap(TextView textView) {
Drawable background = textView.getBackground();
textView.setBackground(null);
int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight();
int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom();
if (width == 0 || height == 0) {
return null;
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop());
textView.draw(canvas);
textView.setBackground(background);
return bitmap;
}
代码示例来源:origin: stackoverflow.com
TextView textView = (TextView) lf.inflate(R.layout.chips_edittext, null);
textView.setText(c); // set text
int image = ((ChipsAdapter) getAdapter()).getImage(c);
textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, image, 0);
// capture bitmapt of genreated textview
int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
textView.measure(spec, spec);
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.translate(-textView.getScrollX(), -textView.getScrollY());
textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
textView.destroyDrawingCache(); // destory drawable
// create bitmap drawable for imagespan
BitmapDrawable bmpDrawable = new BitmapDrawable(viewBmp);
bmpDrawable.setBounds(0, 0,bmpDrawable.getIntrinsicWidth(),bmpDrawable.getIntrinsicHeight());
// create and set imagespan
ssb.setSpan(new ImageSpan(bmpDrawable),x ,x + c.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
内容来源于网络,如有侵权,请联系作者删除!