【问题标题】:Sliding Drawer open from right to left in xamarin android在xamarin android中从右到左打开滑动抽屉
【发布时间】:2018-02-28 09:59:16
【问题描述】:

我在从右到左打开滑动抽屉时遇到问题 xamarin 安卓。但下面的代码适用于显示滑动

抽屉从左到右。如果 MasterDetailPage 的任何属性 打开从右向左滑动 请与我分享您的观点。这里滑动抽屉从左到右打开,但我想从右到左打开 Xamarin 安卓 关于这个的任何想法。请分享你的想法。 我们还使用 MenuRootPage 在滑动抽屉中添加项目:

     Code for items view:
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                               >

        <ContentPage.Content>
            <StackLayout   BackgroundColor="{StaticResource ToolbarStatusBackgroundColor}"  Orientation="Vertical" Spacing="20">
                <StackLayout>
                    <StackLayout.GestureRecognizers>
                        <TapGestureRecognizer Command="{mm:Command SliderClose}" />
                    </StackLayout.GestureRecognizers>
                    <Image Source="menu.png" HorizontalOptions="Start" Margin="10,40,0,0" />
                </StackLayout>
                <BoxView HorizontalOptions="EndAndExpand"  HeightRequest="1" WidthRequest="1000" Color="{StaticResource SeparatorColor}"  />
                <Label Text="My account" Style="{StaticResource ToolbarStatusDescriptionLabel}" Margin="10"  >
                    <Label.GestureRecognizers>
                        <TapGestureRecognizer Command="{mm:Command SliderClose}" />
                    </Label.GestureRecognizers>
                </Label>
                <BoxView HorizontalOptions="EndAndExpand"  HeightRequest="1" WidthRequest="1000" Color="{StaticResource SeparatorColor}"  />

                <Label Text="Settings" Style="{StaticResource ToolbarStatusDescriptionLabel}" Margin="10">
                    <Label.GestureRecognizers>
                        <TapGestureRecognizer Command="{mm:Command SliderClose}" />
                    </Label.GestureRecognizers>
                </Label>
                <BoxView HorizontalOptions="EndAndExpand"  HeightRequest="1" WidthRequest="1000" Color="{StaticResource SeparatorColor}"  />

                <Label Text="Logout" Style="{StaticResource ToolbarStatusDescriptionLabel}" HorizontalTextAlignment="Center"  VerticalOptions="EndAndExpand" Margin="10">
                    <Label.GestureRecognizers>
                        <TapGestureRecognizer  Command="{mm:Command Logout}" />
                    </Label.GestureRecognizers>
                </Label>

            </StackLayout>
        </ContentPage.Content>
    </ContentPage>

        In MenuRootPage .xaml file we are declare master page only UI section
        In MenuRootPage .cs file: here we are inherit MasterDetailPage properties

            Using code:
                     Root page in MenuRootPage .xaml file:
                    <MasterDetailPage  xmlns="http://xamarin.com/schemas/2014/forms"
                                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                                 x:Class="Ansible.Vektor.App.Shared.Views.MenuRootPage" >
                    </MasterDetailPage> 



                    Root MenuRootPage .cs file:
                    public partial class MenuRootPage : MasterDetailPage
                        {
                            public MenuRootPage ()
                            {
                                InitializeComponent();
                                MasterBehavior = MasterBehavior.Popover;

                            }
                        }



            App.xaml.cs:

             var menuPage = new MenuPages() { BindingContext = MenuPagesViewModel };
                        NavigationPage = new NavigationPage(new MainView() { 
                        BindingContext = MainViewModel });
                        MenuRootPage = new MenuRootPage();
                        MenuRootPage.Master = menuPage;
                        MenuRootPage.Detail = NavigationPage;
                        MenuIsGestureEnabled = false;
                        MainPage = MenuRootPage;


                Here Sliding Drawer open from left to right but i want to open from right to left for Xamarin Android
                Any idea regarding this. please share your idea's.

【问题讨论】:

    标签: android xamarin xamarin.forms xamarin.android


    【解决方案1】:

    在 Android 中为主详细信息页面进行自定义渲染。

    public class MyMasterDetailPageRenderer : MasterDetailPageRenderer
    {
        protected override void OnElementChanged(VisualElement oldElement, VisualElement newElement)
        {
            base.OnElementChanged(oldElement, newElement);
            var fieldInfo = GetType().BaseType.GetField("_masterLayout", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var _masterLayout = (ViewGroup)fieldInfo.GetValue(this);
            var lp = new DrawerLayout.LayoutParams(_masterLayout.LayoutParameters);
            lp.Width = 300;
            lp.Gravity = (int)GravityFlags.Right;
            _masterLayout.LayoutParameters = lp;
        }
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多