Android - setLayoutDirection in API 15 and API 16

3.6k views Asked by At

Does anyone know if ViewCompat.setLayoutDirection works in API level below 17?

I search for a solution all over the internet but I can't find a solid one.

1

There are 1 answers

0
Charuක On

setLayoutDirection was added to in API Level 17 (read here) which is 4.2 so the older versions do not support that. So keep two layouts for higher and below and you need to work around for the below api level XML view.

If you're using the support library, you can do the following:

if (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL) {
    //  view -RTL layout
} else {
    //view -  set made layout for below apis 
}

BidiFormatter might help you depending on your requirement.Check that as well.

Every one knows about android:layout_gravity="end" right? can be helpfull in this case