问题描述
我想问一下是否可以在 Xamarin.Forms Shell
中为导航栏或 TabbedPage
(TabLayout
) 设置动画滚动它隐藏或发现看到gif.我在 Xamarin 本机 android 中尝试了它,它在添加 layout_scrollFlags
后工作.
不确定您是否可以在 XF + Shell 中使用 android 样式实现此行为,但是您可以通过覆盖 CreateToolbarAppearanceTracker()
.
公共类 MyShellRenderer : ShellRenderer{公共 MyShellRenderer(上下文上下文):基础(上下文){}受保护的覆盖 IShellToolbarAppearanceTracker CreateToolbarAppearanceTracker(){base.CreateToolbarAppearanceTracker();返回新的 MyShellToolbarAppearanceTracker(this);}}
MyShellToolbarAppearanceTracker(随意命名)
using LP = Android.Views.ViewGroup.LayoutParams;...公共类 MyShellToolbarAppearanceTracker : ShellToolbarAppearanceTracker{公共 MyShellToolbarAppearanceTracker(IShellContext shellContext) : base(shellContext){}public override void SetAppearance(AndroidX.AppCompat.Widget.Toolbar toolbar, IShellToolbarTracker toolbarTracker, ShellAppearance外观){base.SetAppearance(工具栏,toolbarTracker,外观);toolbar.LayoutParameters = new AppBarLayout.LayoutParams(LP.MatchParent, LP.WrapContent){ScrollFlags = AppBarLayout.LayoutParams.ScrollFlagScroll |AppBarLayout.LayoutParams.ScrollFlagEnterAlways};}}
不要忘记使用 ExportRenderer
正确装饰它,如 文档.
(如果以下链接的错误/问题已关闭,请忽略此部分)
已知的副作用
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 导航栏滚动行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!