DrawerLayout中的FrameLayout

时间:2016-12-19 20:20:44

标签: android xamarin

我想将DrawLayout包装成一个FrameLayout(在运行时根据需要将其替换为其他FrameLayouts)。以下代码来自here之上的GitHub项目。

但是如果我在widget.Toolbar下面的LinearLayout中添加一个FrameLayout,我收到以下异常

Unhandled Exception:
System.InvalidCastException: Unable to convert instance of type 'Android.Widget.FrameLayout' to type 'Android.Support.Design.Widget.NavigationView'.

没有FrameLayout它完美无缺。我应该在哪里放置FrameLayout来实现我的目标?

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer_layout"
    android:fitsSystemWindows="true">
  <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <FrameLayout
           android:id="@+id/content_frame"
           android:layout_width="match_parent"
           android:layout_height="match_parent" />    

  </LinearLayout>

  <android.support.design.widget.NavigationView
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:layout_gravity="start"
      android:id="@+id/nav_view"
      app:menu="@menu/navmenu"
      app:headerLayout="@menu/header" />
</android.support.v4.widget.DrawerLayout>

MainAcitivty.cs

    drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);

    // Init toolbar
    var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
    SetSupportActionBar(toolbar);

    // Attach item selected handler to navigation view
    var navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
    navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;

    // Create ActionBarDrawerToggle button and add it to the toolbar
    var drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, Resource.String.open_drawer, Resource.String.close_drawer);
    drawerLayout.AddDrawerListener(drawerToggle);
    drawerToggle.SyncState();

1 个答案:

答案 0 :(得分:1)

&#13;
&#13;
function addMarkerUpstream() {
        var rotate = 0;
        var upstreamIcon = {
            path: 'M28.6,17.5L16.1,4.9l0,0 c-0.1-0.1-0.2-0.2-0.3-0.2c0,0-0.1,0-0.1-0.1c-0.1,0-0.1-0.1-0.2-0.1c-0.1,0-0.1,0-0.2-0.1c0,0-0.1,0-0.1,0c-0.1,0-0.2,0-0.3,0 c0,0,0,0,0,0l0,0c-0.1,0-0.2,0-0.3,0c-0.1,0-0.1,0-0.1,0c-0.1,0-0.1,0-0.2,0.1c-0.1,0-0.1,0.1-0.2,0.1c0,0-0.1,0-0.1,0.1 c-0.1,0.1-0.2,0.1-0.3,0.2c0,0,0,0,0,0l0,0c0,0,0,0,0,0L1,17.5l0,0c-0.7,0.7-0.7,1.8,0,2.5s1.8,0.7,2.5,0l9.6-9.6 c0,6.7,0,34.2,0,34.2c0,1,0.8,1.7,1.7,1.7s1.7-0.8,1.7-1.7V10.4l9.6,9.6c0.7,0.7,1.8,0.7,2.5,0S29.3,18.2,28.6,17.5z',
            fillColor: '#fbb040',
            fillOpacity: 1,
            scale: 1.5,
            strokeColor: '#000',
            strokeWeight: 0.5,
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(15, 50),
            rotation: rotate,
        }

        var marker = new google.maps.Marker({
            position: map.center,
            map: map,
            title: 'Upstream',
            draggable: true,
            icon: upstreamIcon
        });

        latLang = marker.getPosition();

        marker.setMap(map);

        //ROTATION
        $("#rotate").click(function() { 
        rotate = rotate + 5; 
        upstreamIcon.{ rotation: rotate }; // Try like this
        });

        //FILL COLOR
        $("#fill_red").click(function() {
            upstreamIcon = { fillColor: 'red'}
        });
&#13;
&#13;
&#13;