Reputation: 1449
Need to add Quote as a drawable in multiline text like below mentioned screen. Like you can see quote is in a starting of multiline text and next line text is just starting from the below to the quote.
I need to use TextView to achieve this and quote should be a drawable.
If I am using drawableLeft property of TextView Its showing like below mentioned image.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!\nHello World!\nHello World!\nHello World!"
android:drawableStart="@drawable/ic_quote"
android:drawableLeft="@drawable/ic_quote"/>
Upvotes: 3
Views: 2948
Reputation: 148
You can create a SpannableString to add the drawable :
TextView myTextView = (TextView) findViewById(R.id.myTextView);
ImageSpan imageSpan = new ImageSpan(this, R.drawable.ic_quote);
SpannableString spannableString = new SpannableString("*" + myTextView.getText()); // "*" will be replaced by your drawable
int start = 0; // the start index, inclusive
int end = 1; // the end index, exclusive
int flag = 0;
spannableString.setSpan(imageSpan, start, end, flag);
myTextView.setText(spannableString);
And in your layout :
<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!\nHello World!\nHello World!\nHello World!"/>
Upvotes: 5
Reputation: 313
You can use SpannableStringBuilder.
val spannableText = SpannableStringBuilder("*Your text!").apply {
val imageSpan = ImageSpan(context, R.drawable.your_icon)
setSpan(imageSpan, 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
}
textView.setText(spannableText, TextView.BufferType.SPANNABLE)
The symbol * will be raplaced witn your icon.
Upvotes: 0
Reputation: 6073
Try using android:gravity="top"
if it didnt work then go with negative margin like this
android:drawablePadding="-20sp"
Another alternative way is to take an ImageView
beside TextView
inside LinearLayout
so you can apply gravity
Upvotes: 0