简体   繁体   English

Xamarin表单滚动视图和布局

[英]Xamarin forms scrollview and layoutTo not working

I'm creating an app using Xamarin Studio on a Mac. 我正在Mac上使用Xamarin Studio创建应用程序。 The problem I'm facing is that a scrollview only works in the place where it was originally placed at. 我面临的问题是,滚动视图只能在最初放置的地方使用。

I mean, I've a layout that slides to the right and left based on user input (I've two menus, one on the right and the other on the left, you get it). 我的意思是,我有一个根据用户输入左右滑动的布局(我有两个菜单,一个在右边,另一个在左边,就可以了)。 However, if the user doesn't open any menu the scrollview scrolls correctly, if the user does slide, it doesn't work anymore! 但是,如果用户未打开任何菜单,则滚动视图会正确滚动;如果用户滑动,则滚动菜单将不再起作用!

Here's how I'm handling the layout sliding with Xamarin.Forms: 这是我如何使用Xamarin.Forms处理滑动布局的方法:

    public void toggle(){
        Rectangle oldBounds = (Parent as RelativeLayout).Bounds;
        oldBounds.X = -oldBounds.Width/ 3 * (_toggled?0:1);
        (Parent as RelativeLayout).LayoutTo (oldBounds, 600, (_toggled?Easing.CubicOut:Easing.SpringOut));

        _toggled = !_toggled;
    }

Any function I might need to call? 我可能需要调用任何功能吗? For example, forceLayout or something similar? 例如,forceLayout还是类似的东西? I've tried this one and it doesn't work either! 我已经尝试过了,但它也不起作用!

Thanks in advance! 提前致谢!

It may be worth considering to use the Xamarin.Forms MasterDetailPage as this has slide-out functionality inbuilt and works well, although I've experienced mixed results using an emulator in v1.2.2x , but works well on a device. 可能值得考虑使用Xamarin.Forms MasterDetailPage,因为它具有内置的滑出功能并且运行良好,尽管我在v1.2.2x中使用模拟器遇到了混合结果,但在设备上运行良好。

So instead of inheriting from Content Page you could inherit from MasterDetailPage and things will be easier to implement, rather than attempting to write your own. 因此,您可以从MasterDetailPage继承而不是从Content Page继承,这样事情将更易于实现,而不是尝试自己编写。

The only downside to the current MasterDetailPage implementation in Xamarin.Forms is that the slide-out only happens from the left-hand side . Xamarin.Forms中当前MasterDetailPage实现的唯一缺点是滑出仅发生在左侧 This is unfortunately fixed . 不幸的是,这是固定的 You couldn't even specify the fly-out to occur from the right side and also there is no support for dual slide-out areas, from the left and right sides (tested on version 1.2.3x ). 您甚至无法指定从右侧弹出,并且不支持从左侧和右侧进行滑出区域(在1.2.3x版上进行了测试)。 Chances are they will introduce possibly the slide-out direction and possibly dual-slide out areas in a later release but you would need to contact Xamarin on this as to whether its possible and the timeframe for such a feature. 它们可能会在以后的版本中引入滑出方向和双滑出区域,但是您可能需要就此功能是否可能以及这种功能的期限与Xamarin联系。

In your current implementation there appears to be something getting in the way of the ScrollView that is preventing it from doing its normal action, and its not obvious what this is due to how your doing things on your page. 在您当前的实现中,似乎有一些阻碍ScrollView的操作阻止了它执行其正常操作,并且由于您在页面上的操作方式而导致的这种情况并不明显。

There are implementations of dual-sliders on Android , but I haven't looked for iOS , let alone WindowsPhone . Android上有双滑块的实现,但是我没有寻找iOS ,更不用说WindowsPhone了

If you do manage to find them, you could perhaps write a custom renderer to use existing implementations to ease trying to re-create one yourself? 如果您确实设法找到它们,则可以编写一个自定义渲染器以使用现有的实现来简化尝试自己创建的渲染器?

i managed to solve this! 我设法解决了这个! Check the github repository I created with an example. 检查我用示例创建的github存储库 I included a comment on top of DetailView.cs explaining how I did it (hacky way of course! ;) ). 我在DetailView.cs顶部添加了一条注释,解释了我的操作方式(当然,这是一种骇人听闻的方式!;))。

Basically I lay them side by side in a layout that fills all main page and than I use LayoutTo to change that layout Width so that the side menus are hidden. 基本上,我将它们并排放置在充满所有主页的布局中,然后使用LayoutTo更改该布局的Width,以便隐藏侧面菜单。

Than, when you show them aka slide them in, they'll work as expected! 然后,当您向他们展示它们又可以滑入时,它们将按预期工作!

So, thats it, Xamarin.Forms dual panel sliding without any custom rendering! 就是这样,Xamarin.Forms双面板滑动无需任何自定义渲染!

Thanks for your help! 谢谢你的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM