Android画布未在rtl

时间:2017-10-25 09:36:15

标签: android canvas right-to-left

我有以下视图类:

public class MyHorizontalViewIndicator extends View{

     protected synchronized void onDraw(Canvas canvas) {
           super.onDraw(canvas);
           Paint paint = new Paint();
           paint.setTextSize(30);
           canvas.drawText("Test",90, 90, paint);
     }
}



 <com.my.myview.MyHorizontalViewIndicator
    android:id="@+id/view_indicator"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="4dp"
    android:layoutDirection="inherit"/>

当语言为英语时,(LTR)测试消息显示正常,但是,当我将语言更改为阿拉伯语(RTL)时,画布不会显示。

LTR

RTL

2 个答案:

答案 0 :(得分:0)

在Manifest.xml中,您添加了android:supportsRtl

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

将此行canvas.drawText("Test",90, 90, paint);更改为

canvas.drawText("Test",bound.top-100, bound.left-100, paint);

尝试绘制文本的负值

并在xml中更改并尝试layoutDirection = LOCALE

答案 1 :(得分:0)

您可以添加以下代码:

[0]