假设我在ListView中有一个TextView
TextView的值是Name(阿拉伯语)+ "Shared" +Name(英语)。
你所知道的英语是从左到右开始的,而阿拉伯语是从右到左开始的
当两个名字都是用英文写的时候,效果很好
但是当名字是阿拉伯语时,它会像这样
"共享"+名称(英文)+名称(阿拉伯语)
我试过AlignmentSpan.Standard(align . align_opposite)
but it Not Working
下面是我的代码: SpannableString ss = new SpannableString(PostUserName_ + " " + share + " "
+ uname.trim());
ClickableSpan FirstName = new ClickableSpan() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onFirstName(v, position, 3);
}
}
};
ClickableSpan LastName = new ClickableSpan() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onLastName(v, position, 3);
}
}
};
ss.setSpan((new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE)),0, PostUserName_.length() + share.length() + 1+uname.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new TextAppearanceSpan(context,
android.R.style.TextAppearance_Small), PostUserName_.length(),
PostUserName_.length()+share.length()+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(FirstName, 0, PostUserName_.length() ,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(LastName, PostUserName_.length() + share.length() + 2,
PostUserName_.length() + share.length() + 1+uname.length() ,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new RelativeSizeSpan(0.8f), PostUserName_.length() + 1,
PostUserName_.length()+share.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new ForegroundColorSpan(Color.BLACK), 0, PostUserName_.length() + share.length() + 1+uname.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.PostUserName.setVisibility(View.VISIBLE);
holder.PostUserName.setText(ss);
对于任何阿拉伯文本,它都可能默认为RTL布局,要强制LTR,您可以这样做:
。一个格式字符串,用于组合三个字符串,中间有空格:
<string name="three_args_with_spaces_ltr">u202D%1$s %2$s %3$su202C</string>
这些unicode字符强制LTR行为更多信息:https://en.wikipedia.org/wiki/Universal_Character_Set_characters Bidirectional_General_Formatting
如果可能的话,使用英语和阿拉伯语两个textview,并将它们左右对齐。