Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  2. View tagView = inflater.inflate(R.layout.activity_main, null);
  3. TextView name = (TextView) tagView.findViewById(R.id.textView1);
  4. name.setText("hello");
  5.  
  6. //first, View preparation
  7. LayoutInflater inflater =
  8. (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  9. View tagView = inflater.inflate(R.layout.activity_main, null);
  10. TextView name = (TextView) tagView.findViewById(R.id.textView1);
  11. name.setText("hello");
  12.  
  13.  
  14. //second, set the width and height of inflated view
  15. tagView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
  16. MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
  17. tagView.layout(0, 0, tagView.getMeasuredWidth(), tagView.getMeasuredHeight());
  18.  
  19.  
  20. //third, finally conversion
  21. final Bitmap bitmap = Bitmap.createBitmap(tagView.getMeasuredWidth(),
  22. tagView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
  23. Canvas canvas = new Canvas(bitmap);
  24. tagView.draw(canvas);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement