使用阿拉伯字体时的文本对齐问题
下面的屏幕截图显示了我的问题。
第一个 EditText
显示向上移动的阿拉伯语提示,现在第二个 EditText
仅供参考,显示英文版本完全正常。 Button
也是如此。
我已经在 strings.xml
中声明了该字符串,如下所示:
<string name="ar_login">دخول</string>
这就是如何我设置了 EditText 的提示:
UserName.setTypeface(ArabicFont);
String hint = getString(R.string.ar_HintUserName);
....
UserName.setHint(hint);
更新: 我用了这个,但没有用:
UserName.setGravity(Gravity.CENTER_VERTICAL);
但是有了这个,文本向下移动了一点;但我猜它不是通用的:
UserName.setPadding(0,15,0,0);
使用 Padding
时,English
单词会向下移动。
更新2: 最初的阿拉伯文本是分开的;意味着它们逐个字母地显示。因此,为了加入他们,我使用了这个 阿拉伯重塑者。要下载代码,请检查此 链接
现在,当我重塑阿拉伯文本,然后在 TextView
上设置或作为 EditText's
提示时,它会向上移动,但没有重塑它就好了。
所以我想,我是否必须更改重塑类或使我的文本视图不拆分单词。但不知道去哪里?
The screenshot below displays my problem.
The first EditText
shows a hint in Arabic which is shifted upwards, now the second EditText
is just for reference which shows the English version completely fine. Same goes for the Button
.
I have declared the string in strings.xml
like this:
<string name="ar_login">دخول</string>
This is how I set the EditText's hint:
UserName.setTypeface(ArabicFont);
String hint = getString(R.string.ar_HintUserName);
....
UserName.setHint(hint);
UPDATE:
I used this, but of no use:
UserName.setGravity(Gravity.CENTER_VERTICAL);
But with this, Text moved a little down; but i guess its not generic:
UserName.setPadding(0,15,0,0);
With Padding
, English
words move to downwards.
UPDATE 2:
Originally arabic texts are separated; means they are shown letter by letter. So to join them, i was using this Arabic Reshaper. To Download Code, Check this link
Now when i reshape the arabic text and then set on TextView
or as EditText's
Hint, it got shifted upwords but without reshaping it is fine.
So i guess, whether i have to change the reshape class OR make my textview to not split the word. But dont know where to go?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我仍然无法找出为什么 Android 将阿拉伯语单词拆分成单独的字母,无论如何,在我的第二次编辑中,我提供了一个链接,该链接使用一个类重新连接分隔的字母并再次形成一个单词。
在
reshape
函数中,它错误地在末尾附加了\n
,只需将其删除即可解决问题。I am still unable to find out why Android splits the arabic words into separate letters anyhow in my second edit I am providing a link which uses a class to rejoin the separated letters and form a word again.
In the
reshape
function, it was mistakenly appending\n
at the end, just removing it solves the problem.我确信您正在使用的字体文件有问题。!
[抱歉,我不允许上传屏幕截图,因为我的声誉较低:(]
对于布局,我在 xml 中设置文本,在代码中设置字体。而且我没有设置任何属性,如填充/重力。但它 所以,我可以向您保证,
使用样式符合您要求的字体文件将解决您的问题,
但不确定我是否从 DroidSansFallback.ttf
I am sure its problem with the font file which you are using.!
[Sorry I am not allowed to upload the screen shot as my reputations are lower :(]
For the layout, I was setting text in xml, and typeface in code. And I'm not setting any attributes like padding/gravity. But it was working fine for me.
So, I can assure you that using font file whose style matches your requirement will solve your problem.
Just to help you out with, but 'm not sure I got font file from DroidSansFallback.ttf
只是猜测:) ...,
如果阿拉伯字体的尺寸较小怎么办? [如果是这种情况,那么 Gravity.CENTER_VERTICAL 应该适合您:(]
这可能是该字体文件的样式。为阿拉伯文本尝试不同的字体文件怎么样?
Just a guess :) ...,
What if the size of the Arabic font is lower? [If this is the case, then Gravity.CENTER_VERTICAL should have worked for you :( ]
May be this is the style of that font file. How about trying a different font file for Arabic text ?