Multiple alignment in TextView?

左心房为你撑大大i 提交于 2019-11-27 20:08:46

AFAIK this is not possible. I would really aim to have those as two different fields. It seems like you have the data separated, why not just create a separate TextView for the grey text (dictionaryName)?

I have tried to use spannables as less as possible for this very reason.

Andro Selva

Though its really late to answer, I assume that it might help someone at least. Add this to your code.

styledResultText.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), 
text.length() + 2, text.length() + 2 + dictionaryName.length(), 
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Alignment.ALIGN_OPPOSITE is the equivalent for right side.

Alignment.ALIGN_NORMAL is the equivalent for left side.

I think you should split the text into more than 1 string, put them into separated textview then align one by one.

Hope this helps.

If the resultText is always going to be right-aligned, add the gravity="right" attribute to your resultTextView instead of trying to right-align the text with styled spannable strings. This is assuming the grey text is within a separate TextView than your main text.

In xml for the result (grey) text:

<TextView android:id="@+id/resultTextView" 
    android:gravity="right" 
    android:layout_width="fill_parent" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!