Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does setting LayoutDirection on a LinearLayout not take effect immediately?

Tags:

android

I am working on an application, using API 17 (4.2). In the application I am designing a layout class, and I would like to configure it according to the layout direction. However, I haven't been successful in retrieving the applied layout direction within 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 do I configure a layouts direction, and retrieve it within the class?

like image 780
MM. Avatar asked Mar 17 '23 08:03

MM.


1 Answers

add this to your AndroidManifest.xml:

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

As View checks RTL support first, if true, then resolve layout direction.

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

like image 198
Alex.Li Avatar answered Mar 30 '23 00:03

Alex.Li