【问题标题】:Xamarin Forms Java.Lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLYXamarin Forms Java.Lang.IllegalArgumentException:DrawerLayout 必须使用 MeasureSpec.EXACTLY 进行测量
【发布时间】:2015-10-06 06:23:31
【问题描述】:

我将 Auth0 与 Xamarin Forms PCL 库一起使用。 我有以下 MainPage 类:

namespace LoginPattern
{
    public class MainPage : MasterDetailPage
    {
        public MainPage ()
        {
            Master = new MenuPage ();
            Detail = new DetailPage ();
        }
    }
}

并在应用程序类中跟随

public App ()
{   
    Current = this;

    Login ();
}

public void ShowMainPage ()
{   
    MainPage = new MainPage ();
}

public async void Login ()
{
    await DependencyService.Get<IAuth0WidgetLogin>().LoginUseAuth0EmbeddedWidget();
    App.Current.Properties["IsLoggedIn"] = true;

    ShowMainPage ();
}

因此在登录时,我最初没有加载除 Auth0 登录小部件之外的任何页面。成功登录后,我想显示 MasterDetailPage。但我收到以下错误: Java.Lang.IllegalArgumentException:DrawerLayout 必须使用 MeasureSpec.EXACTLY 进行测量。

请告知我是否需要在 NavigationPage 中加载 Widget 以及如何加载。

编辑 17/7 :

public class MenuPage : ContentPage
    {
        MasterDetailPage master;

        TableView tableView;

        public MenuPage ()
        {
            Title = "LoginPattern";
            Icon = "slideout.png";

            var section = new TableSection () {
                new TextCell {Text = "Sessions"},
                new TextCell {Text = "Speakers"},
                new TextCell {Text = "Favorites"},
                new TextCell {Text = "Room Plan"},
                new TextCell {Text = "Map"},
            };

            var root = new TableRoot () {section} ;

            tableView = new TableView ()
            { 
                Root = root,
                Intent = TableIntent.Menu,
            };

            var logoutButton = new Button { Text = "Logout" };
            logoutButton.Clicked += (sender, e) => {
                App.Current.Logout();
            };

            Content = new StackLayout {
                BackgroundColor = Color.Gray,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children = {
                    tableView, 
                    logoutButton
                }
            };
        }


    }


public class DetailPage : ContentPage
{
    public DetailPage ()
    {
        BackgroundColor = new Color (0, 0, 1, 0.2);

        var text = "Slide > to see the master / menu";

        if (Device.OS == TargetPlatform.Android) {
            text = @"Click the action bar dots to see the master / menu";
        } else if (Device.OS == TargetPlatform.WinPhone) {
            text = @"Click button \/ to see the master / menu ";
        }

        Content = new StackLayout { 
            HorizontalOptions = LayoutOptions.Center,
            Padding = new Thickness (10, 40, 10, 10),
            Children = {

                new Label { Text = text }
            }
        };
    }
}

【问题讨论】:

  • 如果我没记错的话,它与 Android 滑出菜单中的尺寸计算有关。您可以为您的 MenuPage 发布代码吗?
  • @WilliamCorncobDecker 添加了 MenuPage 和 DetailPage 代码。

标签: android xamarin.forms auth0


【解决方案1】:

我会尝试做两件事:

  1. 在尝试显示身份验证小部件之前,将应用程序的 MainPage 设置为空白页面(或类似启动页面)。
  2. 在您的 MenuPage 上设置显式宽度请求。

【讨论】:

    【解决方案2】:

    只是为了帮助他人,以下是我的最终解决方案:

    public class MainPage : MasterDetailPage
    {
        public MainPage ()
        {
            Master = new MenuPage (this);
            Detail = new DetailPage ();
            ShowLoginDialog ();
        }
    
        async void ShowLoginDialog()
        {
            var page = new LoginPage();
    
            await Navigation.PushModalAsync(page);
    
            App.Current.Login ();
            await Navigation.PopModalAsync();
        }
    }
    

    PS:LoginPage 只是一个空的 ContentPage。

    【讨论】:

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