2
I have a Pan image, but it only works with images, when I try to use a Hape the location of the image is as if n has no image, but also does not present any error.
String text = exercicios.get(0).getPergunta();
Log.i(TAG, exercicios.get(0).getPergunta());
//String text = "texto # texto";
//Posição onde colocar a imegem(posição da marca)
int imagePos = text.indexOf("#");
//Criar um SpannableString do texto
SpannableString spannableString = new SpannableString(text);
//Obter o drawable a inserir
Drawable drawable = getResources().getDrawable(R.drawable.shapepergunta);
drawable.setBounds(0, 0,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
//Criar um ImageSpan do drawable
ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
//Inserir a imagem(ImageSpan) no texto(SpannableString)
spannableString.setSpan(imageSpan,imagePos,imagePos+1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
//Atribuir o texto com a imagem ao TextView
txvpergunta.setText(spannableString);
Shape:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<gradient
android:angle="45"
android:centerX="35%"
android:centerColor="#198CFF"
android:startColor="#449DEF"
android:endColor="#2F6699"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<stroke
android:width="1dp"
android:color="#878787"
/>
</shape>
Put the Shape xml.
– ramaral
posted @ramaral
– Igor Oliveira