回答我自己的问题。
查遍之后我没有找到答案。因为 ROM 是为居住在以色列并讲希伯来语的人定制的,所以宽度 MATCH_PARENT TextView 内的对齐方式似乎被翻转了。意思是,左对齐意味着右对齐,右对齐意味着左对齐。
改变这一点的唯一方法是将 TextView 与 WRAP_CONTENT 一起使用,并将 TextView 本身与其父级内部的右侧对齐。
因为我已经编写了应用程序和所有屏幕布局,所以我不想更改所有内容。
因此,我所做的是实现一个自定义控件,它将 TextView 包装在 LinearLayout 内,并将其公开以方便从外部使用。
这样,MATCH_PARENT 将影响 LinearLayout,而控件将负责将包装的 TextView 向右对齐。
方法如下:
首先,控件类本身(HebrewTextView.java):
public class HebrewTextView extends LinearLayout
{
private TextView mTextView;
public HebrewTextView(Context context)
{
super(context);
init(null);
}
public HebrewTextView(Context context, AttributeSet attrs)
{
super(context, attrs);
init(attrs);
}
public TextView getTextView()
{
return mTextView;
}
private void init(AttributeSet attrs)
{
mTextView = new TextView(getContext());
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
lp.gravity = Gravity.RIGHT;
mTextView.setLayoutParams(lp);
mTextView.setGravity(Gravity.CENTER_VERTICAL);
addView(mTextView);
if(attrs!=null)
{
TypedArray params = getContext().obtainStyledAttributes(attrs, R.styleable.HebrewTextView);
mTextView.setText(params.getString(R.styleable.HebrewTextView_android_text));
mTextView.setTextColor(params.getColor(R.styleable.HebrewTextView_android_textColor, Color.WHITE));
mTextView.setTextSize(params.getDimension(R.styleable.HebrewTextView_android_textSize, 10));
mTextView.setSingleLine(params.getBoolean(R.styleable.HebrewTextView_android_singleLine, false));
mTextView.setLines(params.getInt(R.styleable.HebrewTextView_android_lines, 1));
params.recycle();
}
}
}
Values/attrs.xml 下的控件 XML 属性。请注意,自定义属性与 TextView 属性匹配,因此我不必更改布局文件:
注意:这些是我需要的属性,如果您要使用更多属性,只需添加到 XML 并在类的 init() 中读取它即可。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="HebrewTextView">
<attr name="android:text"/>
<attr name="android:textColor"/>
<attr name="android:lines"/>
<attr name="android:textSize"/>
<attr name="android:singleLine"/>
</declare-styleable>
</resources>
完成之后,我所要做的就是运行有问题的布局,并将 TextView 替换为希伯来文本视图,如果它是代码引用的 TextView,则更改转换。
getTextView() 方法是在控件类中定义的,以便代码中更改文本和/或其他 TextView 属性的部分在添加 .getTextView() 后缀后将起作用。
希望有帮助。