Android changing language configuration messes up layout

纵饮孤独 提交于 2019-12-11 03:13:02

问题


So I'm trying to add hebrew support to my android app. I had to change the version to 2.2 so it would have built-in hebrew fonts. Some things in the layout has messed up but I fixed them.

But one thing has left - for some reason, when forcing hebrew locale, ONE of my layouts gets messed up... No idea why. And even when using the SAME layout for both locales (English and Hebrew) it's still get messed up this way (But the texts still stick to the left)

Here is the normal layout (Graph is taking full screen)

And here is the messed one:

Both xml layouts are the same, but the hebrew layout has 'android:gravity="right"' set on the textviews.

Here is the code to change locale and configuration. 'setContentView' is called right after this.

        Locale locale = new Locale("iw");
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config,  getBaseContext().getResources().getDisplayMetrics());

And if I'm already asking... Is there any way to set rtl reading in android? As you can see, the hebrew layout has messed up the text rtl too.

I have tried to use the rtl unicode character \u200f, but as you can see it didn't help at all....

Any ideas? Thanks.


回答1:


I had to add this in the manifest:

  <supports-screens
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="true"
    android:anyDensity="true"
    />

And it worked.



来源:https://stackoverflow.com/questions/7289060/android-changing-language-configuration-messes-up-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!