[NativeScript Android] Can't set tabmode fixed in Tabbar

android

#1

Hi,
I have a question about Tabbar in Native Script. In native mode I can set the tabmode with value fixed: in this way the tabbar it isn’t scrollable; but in native script i can’t set tabmode=fixed on tabbar. Why? Am I doing something wrong?
Thanks


#2

NativeScript doesn’t use the TabLayout from Android support library but implements it’s own layout just like the one in support library. You may achieve the similar look and feel by adding the code below to your tab view’s load event.

   onTabViewLoaded(event: EventData) {
        if (isAndroid) {
            const tabView = (<any>event.object)._tabLayout.getChildAt(0),
                tabsCount = tabView.getChildCount(),
                maxWidth = screen.mainScreen.widthPixels / tabsCount;

            for (let i = 0; i < tabsCount; i++) {
                const tabItem = tabView.getChildAt(i),
                    textView = tabItem.getChildAt(1);
                tabItem.setLayoutParams(
                    new android.widget.LinearLayout
                        .LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                        android.view.ViewGroup.LayoutParams.MATCH_PARENT)
                );
                textView.setMaxWidth(maxWidth); 
                textView.setMaxLines(1);
            }
        }
    }

#3

Thank you so much.
It’s a beautiful solution.