如何以编程方式创建NavigationView

时间:2016-09-07 17:09:02

标签: android xamarin.android android-navigation-drawer

我正在尝试以编程方式创建导航抽屉,这一切都可以阻止导航视图覆盖屏幕并阻止其他内容。我已经删除了导航视图,并且内容再次正确显示。

private View SetupNavigationView() {
    fullLayout = new DrawerLayout(this);
    fullLayout.LayoutParameters = new DrawerLayout.LayoutParams(DrawerLayout.LayoutParams.MatchParent, DrawerLayout.LayoutParams.MatchParent);
    fullLayout.SetFitsSystemWindows(true);
    fullLayout.SetBackgroundColor(Color.Black);

    LinearLayout relLayout = new LinearLayout(this);
    relLayout.LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
    relLayout.Orientation = Orientation.Vertical;
    relLayout.WeightSum = 100;

    toolbar = new SupportToolbar(this);
    LinearLayout.LayoutParams tParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent,0, 10);
    toolbar.LayoutParameters = tParams;
    toolbar.SetBackgroundColor(Color.Gray);
    toolbar.SetMinimumHeight(50);

    activityContainer = new FrameLayout(this);   
    activityContainer.LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent,0,90);
    relLayout.AddView(toolbar);
    relLayout.AddView(activityContainer);    
    fullLayout.AddView(relLayout);

    navigationView = new NavigationView(this);
    DrawerLayout.LayoutParams navLayout = new DrawerLayout.LayoutParams(DrawerLayout.LayoutParams.WrapContent,                                      DrawerLayout.LayoutParams.MatchParent);
    navigationView.LayoutParameters = navLayout;
    navigationView.SetBackgroundColor(Color.Blue);
    navigationView.SetFitsSystemWindows(true);
    //navLayout.Gravity = GravityFlags.Start; 
    //Had to comment this out as DrawerLayout.LayoutParams does not implement Layout Gravity.

    fullLayout.AddView(navigationView);
    return fullLayout;
}

我最初尝试使用LinearLayout.LayourParams作为导航视图,但这仍然没有什么区别。我花了相当多的时间在这上面工作,所以这是我需要工作的最后一块。感谢您提供任何帮助或建议。

0 个答案:

没有答案