Why doesn't setting the LayoutDirection on LinearLayout take effect immediately?

I am working on an application using API 17 (4.2). In the application, I am developing a layout class, and I would like to customize it according to the direction of the layout. However, I could not find the applied layout direction in the class:

LinearLayout layout = newLayout(context);
layout.setLayoutDirection(LAYOUT_DIRECTION_RTL);
int ld = layout.getLayoutDirection();    // STILL 0! I was expecting 1

My question is: how to adjust the direction of the layouts and get it in the class?

+4
source share
1 answer

add this to your AndroidManifest.xml:

<application 
    ...
    android:supportsRtl="true"
    >

As shown, it first checks for RTL support if true, and then allows layout direction.

You can get more details at View.resolveLayoutDirection().

+7
source

All Articles