android - 如何调整阿拉伯语 'aarab'字符?请看我的代码

标签 android textview

我正在尝试使用自定义字体显示阿拉伯语文本。我的代码如下:

package com.androidbook.test;

import java.io.BufferedInputStream;
import java.io.InputStream;

import org.apache.http.util.ByteArrayBuffer;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

public class ArabicTextActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.arabic_display);

        TextView arabicTextView;
          Typeface arabicFont;

          arabicTextView = (TextView)findViewById(R.id.arabicTextDisplayTextView);
          arabicFont =Typeface.createFromAsset(getAssets(),"me_quran.ttf");
          arabicTextView.setTypeface(arabicFont);     
          arabicTextView.setTextSize(40);

            InputStream is = getResources().openRawResource(R.raw.arabic_text); 
            BufferedInputStream bis = new BufferedInputStream(is);
            int myInt=0;

            try{
                ByteArrayBuffer myByteArray = new ByteArrayBuffer(100); 
                while((myInt = bis.read())!=-1)
                {
                    if(myInt == 10) break;
                    myByteArray.append((byte)myInt);
                }

                String arabicLine = new String(myByteArray.toByteArray(), 0, myByteArray.length(), "UTF-8");
                arabicTextView.setText(arabicLine);
            }catch(Exception ex)
            {
                ex.printStackTrace();
            }
    }

}

和 arabic_display.xml 是:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/quranDisplayItemLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:orientation="vertical">

        <TextView
            android:id="@+id/arabicTextDisplayTextView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Arabic" />

    </LinearLayout> 

其中 res/raw/as arabic_text.txt 在记事本中显示为(字体名称:me_quran.ttf 和字体大小 40)

enter image description here

但在模拟器中显示为:

enter image description here

您会注意到小字符(在阿拉伯语中称为 aaraab 字符)根本没有调整。我应该如何解决这个问题? ///////////////////////////////////////////////////////////////// ///////////

//// /////

使用 DroidSansArabic.ttf 后的结果

enter image description here

最佳答案

这是我的字体。它是一种有效的 opentype 字体,并且具有大多数其他阿拉伯语字体所没有的一些高级功能。

这里的问题是 Android。它的阿拉伯语支持太基础了,它不理解这种字体具有的高级排版功能。您将无法获得良好的阿拉伯语显示。你能得到的最好的可能是像 tahoma 这样的东西,它使用相同的位置作为变音符号。

为了解决这个问题,我更新了字体以使其适用于 Android 和 Iphone。不幸的是,由于这些平台的性质,人们永远无法使用标准阿拉伯语文本来获得良好的阿拉伯语支持。我所做的是使用修改后的文本,以便获得我想要的结果。结果是基本字体,但比那些系统字体好看得多。对不起,我不能发布图片(这里是新用户)

提醒一下,me_quran 不是免费字体。它仅对免费项目免费。如果您想获得我的解决方案,可以直接与我联系。

关于android - 如何调整阿拉伯语 'aarab'字符?请看我的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9256149/

相关文章:

java - 如何访问另一个布局的元素?

java - 如何制作一个 TextView 来绕过 Android 中的其他 TextView?

java - Android实现了一个带有两个clip textview的progressBar

java - 我正在尝试从android studio内部存储中的.txt文件中读取文本

android - 从 Android 设备连接到本地服务器

android - Nexus one 未显示在 DDMS 问题中

Android:显示警报对话框时 AsynTask 使应用程序崩溃

平板电脑的 Android fragment 导航 - 单个或多个 Activity ?

java - Android TextView 中显示奇怪或随机的 UTF8 字符

android - ellipsize=end 用省略号替换整个最后一行