Java 如何动态有效地应用RTL
每当我应用Java 如何动态有效地应用RTL,java,android,android-layout,textview,right-to-left,Java,Android,Android Layout,Textview,Right To Left,每当我应用layoutAmount.setRotationY(180)时,我都在线性布局中动态地创建和添加文本视图版面改变了方向,这是正确的,但版面内文本视图的文字也改变了方向,这是错误的,例如,如果文字“对不起”,它变成了yrros,我如何正确应用RTL 谢谢 使布局动态RTL的最佳方法是: 如果您使用ConstraintLayout 不要使用左右两侧的 相反,请使用start和end 当您更改区域设置时,Android将动态更改布局 您可以找到我关于如何按区域设置更改应用程序语言的答案 更新
layoutAmount.setRotationY(180)时,我都在线性布局中动态地创建和添加文本视图代码>版面改变了方向,这是正确的,但版面内文本视图的文字也改变了方向,这是错误的,例如,如果文字“对不起”,它变成了yrros,我如何正确应用RTL
谢谢 使布局动态RTL的最佳方法是:
如果您使用ConstraintLayout
不要使用左右两侧的
相反,请使用start和end
当您更改区域设置时,Android将动态更改布局
您可以找到我关于如何按区域设置更改应用程序语言的答案
更新:
年轻时
将约束用作
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/imageView_about_back"
app:layout_constraintTop_toTopOf="parent"
另外,不要使用左边距或右边距
如果是线性布局
使用重力起点和终点
示例代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_image"
tools:context=".activity.HomeActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"
android:text="@string/about_al_ameen"
android:textColor="@color/colorWhite" />
</LinearLayout>
使布局动态RTL的最佳方法是:
如果您使用ConstraintLayout
不要使用左右两侧的
相反,请使用start和end
当您更改区域设置时,Android将动态更改布局
您可以找到我关于如何按区域设置更改应用程序语言的答案
更新:
年轻时
将约束用作
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/imageView_about_back"
app:layout_constraintTop_toTopOf="parent"
另外,不要使用左边距或右边距
如果是线性布局
使用重力起点和终点
示例代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_image"
tools:context=".activity.HomeActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"
android:text="@string/about_al_ameen"
android:textColor="@color/colorWhite" />
</LinearLayout>
当您选择语言添加时
LocaleHelper.setLocale(LAngSelect.this, "ar");
然后用sqlite或其他工具保存它
然后有目的地转到MainActivity:
在MainActivity上保存语言并添加:
if (langs.equals("ar")) {
forceRTLIfSupported();
}
private void forceRTLIfSupported()
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
//HERE CHECK CONDITION FOR YOUR LANGUAGE if it is AR then
//change if it is english then don't
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
}
当你选择语言添加
LocaleHelper.setLocale(LAngSelect.this, "ar");
然后用sqlite或其他工具保存它
然后有目的地转到MainActivity:
在MainActivity上保存语言并添加:
if (langs.equals("ar")) {
forceRTLIfSupported();
}
private void forceRTLIfSupported()
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
//HERE CHECK CONDITION FOR YOUR LANGUAGE if it is AR then
//change if it is english then don't
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
}
设置布局方向将根据语言设置布局方向
-确保使用布局重力开始和结束
public static void setLanguage(Context context, String language) {
String[] localeLang = language.split("_");
Locale locale;
if (localeLang.length > 1)
locale = new Locale(localeLang[0], localeLang[1]);
else
locale = new Locale(localeLang[0]);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
config.setLayoutDirection(locale);
((Activity) context).getWindow().getDecorView().setLayoutDirection(config.getLayoutDirection());
}
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
}
设置布局方向将根据语言设置布局方向
-确保使用布局重力开始和结束
public static void setLanguage(Context context, String language) {
String[] localeLang = language.split("_");
Locale locale;
if (localeLang.length > 1)
locale = new Locale(localeLang[0], localeLang[1]);
else
locale = new Locale(localeLang[0]);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
config.setLayoutDirection(locale);
((Activity) context).getWindow().getDecorView().setLayoutDirection(config.getLayoutDirection());
}
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
}
你想让RTL的版面轮换像阿拉伯语版面是RTL的阿拉伯文我的答案,让我知道它的工作与否你想让RTL的版面轮换像阿拉伯语版面是RTL的阿拉伯文我的答案,让我知道它的工作与否not@blackHawk我更新了答案,还有文本线性布局示例view@blackHawk我更新了答案,还提供了文本视图的线性布局示例