daphliu-zz / android-spannable-list-sample

MIT License
21 stars 3 forks source link

Bullet points alignment with RTL Locales #3

Open mojojojo42 opened 1 month ago

mojojojo42 commented 1 month ago

Hi @daphliu-zz @NotWoods,

Your custom Html.TagHandler, i.e., ListTagHandler, is a great help and works fine with the Left-to-Right Locales in Android. But it's not working as expected with the Right-to-Left Locales, e.g., Persian or Arabic.

Please check the screenshot below: img_html_tag_issue

I tried a few changes in the ListTagHandler but that didn't work. I appreciate any help you can provide.

dheeraj-su commented 1 month ago

Hello, I've resolved the above-mentioned issue by adding a small piece of code in TextLeadingMarginSpan.kt. Inside the drawLeadingMargin(...), I'm calculating the x-axis,i.e., trueX, value for RTL Locales.

val trueX: Int =
        if (dir > 0) {
            /* For Locale direction: LTR, i.e., English, German, etc. */
            marginWidth * indentation
        } else {
            /* For Locale direction: RTL, i.e., Arabic, Persian, etc. */
            c.width - if (marginWidth * indentation == 0) {
                p.measureText(string).toInt()
            } else {
                marginWidth * indentation
            }
        }