本文整理了Java中android.widget.TextView.setDrawingCacheEnabled()
方法的一些代码示例,展示了TextView.setDrawingCacheEnabled()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.setDrawingCacheEnabled()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:setDrawingCacheEnabled
暂无
代码示例来源:origin: stackoverflow.com
public Drawable createFromView(int positionNumber)
{
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.drawable.pin_icon, null, false);
TextView tv = (TextView) view.findViewById(R.id.pin_background);
tv.setText(" "+ (positionNumber+1) ); // +1 since position is starting from 0
tv.setDrawingCacheEnabled(true);
tv.layout(0, 0, 50, 50);
tv.buildDrawingCache();
Bitmap b = Bitmap.createBitmap(tv.getDrawingCache());
tv.setDrawingCacheEnabled(false);
Drawable d = new BitmapDrawable(b);
return d;
}
代码示例来源:origin: stackoverflow.com
TextView yourView = new TextView(this);
yourView.setText("text");
yourView.setBackgroundResource(R.drawable.background_resource);
// taken from the other ticket
Bitmap snapshot = null;
Drawable drawable = null;
yourView.setDrawingCacheEnabled(true);
yourView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); //Quality of the snpashot
try {
snapshot = Bitmap.createBitmap(yourView.getDrawingCache(), sizes and stuff); // You can tell how to crop the snapshot and whatever in this method
drawable = new BitmapDrawable(snapshot)
} finally {
yourView.setDrawingCacheEnabled(false);
}
mySeekBar.setThumb(drawable);
代码示例来源:origin: stackoverflow.com
Paint paint1 = new Paint();
paint1.setStyle(Paint.Style.FILL);
paint1.setAntiAlias(true);
paint1.setColor(Color.BLACK);
paint1.setTextSize(15);
TextView tv = new TextView(context);
tv.setTextColor(Color.BLACK);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llp.setMargins(5, 2, 0, 0); // llp.setMargins(left, top, right, bottom);
tv.setLayoutParams(llp);
tv.setTextSize(10);
String text="this is good to see you , i am the king of the team";
tv.setText(text);
tv.setDrawingCacheEnabled(true);
tv.measure(MeasureSpec.makeMeasureSpec(canvas.getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(canvas.getHeight(), MeasureSpec.EXACTLY));
tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());
canvas.drawBitmap(tv.getDrawingCache(), 5, 10, paint1);
tv.setDrawingCacheEnabled(false);
代码示例来源: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
public void run() {
tv.setDrawingCacheEnabled(true);
tv.buildDrawingCache();
代码示例来源:origin: stackoverflow.com
send = (Button) findViewById(R.id.button);
tv1 = (TextView) findViewById(R.id.outputc);
tv1.setDrawingCacheEnabled(true);
代码示例来源:origin: easemob/kefu-android-demo
private Bitmap creatCodeBitmap(String contents, int width, int height, Context context) {
TextView tv = new TextView(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
tv.setLayoutParams(layoutParams);
tv.setText(contents);
tv.setHeight(height);
tv.setGravity(Gravity.CENTER_HORIZONTAL);
tv.setWidth(width);
tv.setDrawingCacheEnabled(true);
tv.setTextColor(Color.BLACK);
tv.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());
tv.buildDrawingCache();
Bitmap bitmapCode = tv.getDrawingCache();
return bitmapCode;
}
代码示例来源:origin: stackoverflow.com
EditText editText = (EditText) findViewById(R.id.editText);
TextView textView = new TextView(this.getApplicationContext());
textView.setTypeface(editText.getTypeface());
textView.setText(editText.getText());
textView.measure(
View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
textView.setDrawingCacheEnabled(true);
textView.buildDrawingCache();
Bitmap b = textView.getDrawingCache().copy(Bitmap.Config.ARGB_8888, false);
textView.destroyDrawingCache();
try{
String path = Environment.getExternalStorageDirectory().toString() + "/picture.png";
OutputStream outputStream = new FileOutputStream(new File(path));
b.compress(Bitmap.CompressFormat.PNG, 0, outputStream);
outputStream.flush();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
代码示例来源:origin: stackoverflow.com
// String to bitmap
public Bitmap StringToBitMap(String encodedString){
TextView textView = new TextView(StoryActivity.this);
textView.layout(30, 300, 300, 500);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 12);
textView.setTextColor(Color.BLACK);
textView.setText(encodedString);
textView.setDrawingCacheEnabled(true);
textView.setDrawingCacheQuality(2);
return Flip(textView.getDrawingCache()) ;
}
// flip picture
private Bitmap Flip(Bitmap asset) {
Matrix mat = new Matrix();
mat.postScale(-1F, 1F);
int width = asset.getWidth();
int height = asset.getHeight();
return Bitmap.createBitmap(asset, 0, 0, width, height, mat, true);
}
代码示例来源:origin: stackoverflow.com
tv.setGravity(Gravity.BOTTOM);
tv.setPadding(8, 8, 8, 50);
tv.setDrawingCacheEnabled(true);
tv.measure(MeasureSpec.makeMeasureSpec(canvas.getWidth(),
MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(
tv.setDrawingCacheEnabled(false);
iv.setDrawingCacheEnabled(false);
parent.setDrawingCacheEnabled(false);
代码示例来源:origin: pchauhan/EdittextWithTag
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);
代码示例来源:origin: AmaldevTA/ChipLayout
private SpannableStringBuilder textToChip(String val, boolean trim){
SpannableStringBuilder ssb = new SpannableStringBuilder(val);
try{
TextView textView = createAutoCompleteTextView(context);
if (trim){
textView.setText(val.substring(0, ChipLayout.MAX_CHARACTER_COUNT)+"..");
}else {
textView.setText(val);
}
int spec = View.MeasureSpec.makeMeasureSpec(0, View.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();
BitmapDrawable bmpDrawable = new BitmapDrawable(context.getResources(), viewBmp);
bmpDrawable.setBounds(0, 0, bmpDrawable.getIntrinsicWidth(), bmpDrawable.getIntrinsicHeight());
ssb.setSpan(new ImageSpan(bmpDrawable), 0, val.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}catch (Exception e){}
return ssb;
}
代码示例来源:origin: stackoverflow.com
-textView.getScrollY());
textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888,
代码示例来源: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);
内容来源于网络,如有侵权,请联系作者删除!