带有FreshTabbedNavigationContainer的可滚动标签栏

时间:2018-04-13 06:57:04

标签: xamarin xamarin.forms xamarin.android freshmvvm

使用FreshMVVM的FreshTabbedNavigationContainer所有标签都希望同时显示并截断:

enter image description here

我希望它们是全宽和可滚动的,就像使用常规TabbedPage

一样

enter image description here

我实际上并没有这么多标签。这只是一个展示我的意思的例子。

1 个答案:

答案 0 :(得分:1)

您需要使用CustomRednerer 例如:
在Droid项目中:

[assembly: ExportRenderer(typeof(ScrollableTabbedPage), typeof(ScrollableTabbedPageRenderer))]
namespace ScrollableFreshTabbed.Droid
{
    class ScrollableTabbedPageRenderer : TabbedPageRenderer
    {
        public ScrollableTabbedPageRenderer(Context context) : base(context)
        {

        }
        public override void OnViewAdded(Android.Views.View child)
        {
            base.OnViewAdded(child);
            var tabLayout = child as TabLayout;
            if (tabLayout != null)
            {
                tabLayout.TabMode = TabLayout.ModeScrollable;
            }
        }    
    }
}

在便携式项目中:

public class ScrollableTabbedPage :  FreshTabbedNavigationContainer
{
    public ScrollableTabbedPage ()
    {

    }
}

App.xaml.cs:

        public App ()
        {
            InitializeComponent();
            var tabbedNavigation = new ScrollableTabbedPage();
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);
            tabbedNavigation.AddTab<QuotePageModel>("Contacts", null);

            MainPage = tabbedNavigation;    
        }

结果是:
enter image description here