回答我自己的问题。
翻遍后,我没有找到答案。因为 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() 方法是在控件类中定义的,因此在添加 .getTextView() 后缀后,代码中更改文本和/或其他 TextView 属性的部分将起作用。
希望对您有所帮助。