
I am trying to align the TextView around ImageView. I am using the following code:
private void createSpannableText(){
TextView myTextView = (TextView) findViewById(R.id.textView);
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(this.getText(R.string.loren__ipsum__max));
int lengthOfPart1 = builder.length();
builder.append(" ");
builder.append(this.getText(R.string.lorem__ipsum));
Drawable d = getResources().getDrawable(R.drawable.myImage);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); // <---- Very important otherwise your image won't appear
ImageSpan myImage = new ImageSpan(d);
builder.setSpan(myImage, 0, lengthOfPart1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
myTextView.setText(builder);
}
But couldn't get the exact result. What shall I do? Do I need to use SpannableStringBuilder in this case or there is another way. Please help. I used this post-http://majaxandroidtips.blogspot.in/2009/06/how-to-have-few-layout-elements-wrap_17.html to have the solution.
P.S.: I also want 6dp margin around the ImageView