Shell导航栏滚动行为 [英] Shell navigation bar scroll behavior

查看:87
本文介绍了Shell导航栏滚动行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问问是否可以对Xamarin.Forms Shell 中的导航栏或 TabbedPage ( TabLayout )进行动画处理.滚动隐藏或发现,请参见gif.我在Xamarin本机android中尝试过,在添加 layout_scrollFlags 后可以正常工作.

解决方案

不确定在XF + Shell中是否可以使用android样式实现此行为,但是可以通过重写 CreateToolbarAppearanceTracker().

 公共类MyShellRenderer:ShellRenderer{公共MyShellRenderer(上下文上下文):base(上下文){}受保护的重写IShellToolbarAppearanceTracker CreateToolbarAppearanceTracker(){base.CreateToolbarAppearanceTracker();返回新的MyShellToolbarAppearanceTracker(this);}} 

MyShellToolbarAppearanceTracker (随意命名)

 使用LP = Android.Views.ViewGroup.LayoutParams;...公共类MyShellToolbarAppearanceTracker:ShellToolbarAppearanceTracker{公共MyShellToolbarAppearanceTracker(IShellContext shellContext):base(shellContext){}公共重写void SetAppearance(AndroidX.AppCompat.Widget.Toolbar工具栏,IShellToolbarTracker工具栏跟踪器,ShellAppearance外观){base.SetAppearance(工具栏,工具栏跟踪器,外观);工具栏.LayoutParameters =新的AppBarLayout.LayoutParams(LP.MatchParent,LP.WrapContent){ScrollFlags = AppBarLayout.LayoutParams.ScrollFlagScroll |AppBarLayout.LayoutParams.ScrollFlagEnterAlways};}} 

不要忘记按照 Xamarin.Forms错误13338

I would like to ask if it is possible to animate the Navigation Bar or TabbedPage (TabLayout) in the Xamarin.Forms Shell when scrolling it either hides or the discovery see gif. I tried it in Xamarin native android there it works after adding layout_scrollFlags.

http://lomza.totem-soft.com/appbarlayout-scroll-behavior-with-layout_scrollflags

http://karthikraj.net/2016/12/24/scrolling-behavior-for-appbars-in-android

解决方案

Not sure if you can achieve this behavior with an android style in XF + Shell, but you can achieve it using a custom renderer by overriding CreateToolbarAppearanceTracker().

    public class MyShellRenderer : ShellRenderer
    {
        public MyShellRenderer(Context context) : base(context)
        {
        }

        protected override IShellToolbarAppearanceTracker CreateToolbarAppearanceTracker()
        {
            base.CreateToolbarAppearanceTracker();
            return new MyShellToolbarAppearanceTracker(this);
        }
    }

MyShellToolbarAppearanceTracker (name it whatever you want)

using LP = Android.Views.ViewGroup.LayoutParams;
...
public class MyShellToolbarAppearanceTracker : ShellToolbarAppearanceTracker
{
        public MyShellToolbarAppearanceTracker(IShellContext shellContext) : base(shellContext)
        {
        }

        public override void SetAppearance(AndroidX.AppCompat.Widget.Toolbar toolbar, IShellToolbarTracker toolbarTracker, ShellAppearance appearance)
        {
            base.SetAppearance(toolbar, toolbarTracker, appearance);
            toolbar.LayoutParameters = new AppBarLayout.LayoutParams(LP.MatchParent, LP.WrapContent)
            {
                ScrollFlags = AppBarLayout.LayoutParams.ScrollFlagScroll |
                AppBarLayout.LayoutParams.ScrollFlagEnterAlways
            };
        }
}

Don't forget to properly decorate it with ExportRenderer as explained in the documentation.


(ignore this section if the below linked bug/issue is closed)

Known Side-Effect

This is a trivial undesired side-effect caused by a Xamarin.Forms Bug 13338

这篇关于Shell导航栏滚动行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆