回答我自己的问题。
看完了所有我没有找到答案。由于ROM是为居住在以色列并讲希伯来语的人定制的,因此看起来MATCH_PARENT TextView宽度内的对齐方式被翻转了。含义,左对齐意味着左右。 要改变这一点,唯一的方法是使用带有WRAP_CONTENT的TextView,并将TextView自身对齐到其父项的右侧。 因为我已经编写了应用程序和所有的屏幕布局,我不想改变一切。 所以我所做的是实现了一个自定义控件,它将一个TextView包装在一个LinearLayout中,并从外部方便地使用它。 这样,MATCH_PARENT将影响LinearLayout,而控件将负责将包装的TextView对齐到右侧。
这该是多么:
首先,控制类本身(HebrewTextView.java):在值/ attrs.xml
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();
}
}
}
控制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>
后做好了所有我所要做的就是在问题的布局运行并与HebrewTextView更换TextView的,如果这是由代码中引用一个TextView,改变铸造。 getTextView()方法在控件类中定义,以便在添加.getTextView()后缀后,代码中用于更改文本和/或其他TextView属性的部分将起作用。
希望有所帮助。