Guest User

Untitled

a guest
Jan 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. String text = exercicios.get(0).getPergunta();
  2. Log.i(TAG, exercicios.get(0).getPergunta());
  3. //String text = "texto # texto";
  4.  
  5. //Posição onde colocar a imegem(posição da marca)
  6. int imagePos = text.indexOf("#");
  7.  
  8. //Criar um SpannableString do texto
  9. SpannableString spannableString = new SpannableString(text);
  10.  
  11. //Obter o drawable a inserir
  12. Drawable drawable = getResources().getDrawable(R.drawable.shapepergunta);
  13. drawable.setBounds(0, 0,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
  14.  
  15. //Criar um ImageSpan do drawable
  16. ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
  17. //Inserir a imagem(ImageSpan) no texto(SpannableString)
  18. spannableString.setSpan(imageSpan,imagePos,imagePos+1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  19. //Atribuir o texto com a imagem ao TextView
  20. txvpergunta.setText(spannableString);
Add Comment
Please, Sign In to add comment