Android Recycle视图阻止工具栏在4.4.9设备上打开导航抽屉,适用于6.0设备

时间:2016-03-23 21:09:07

标签: c# android xamarin

我有这样的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/DrawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="@color/backgroundColor">
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".MainActivity">
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:elevation="2dp"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:minHeight="?attr/actionBarSize"
                android:background="?attr/colorPrimary" />
        </android.support.design.widget.AppBarLayout>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:scrollbars="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/panic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="16dp"
            app:backgroundTint="@color/panicButton"
            android:src="@drawable/ic_0005_panic_button_icon" />
    </android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.NavigationView
        android:fitsSystemWindows="true"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:id="@+id/nav_view"
        app:headerLayout="@layout/header"
        app:menu="@menu/navigationviewmenu" />
</android.support.v4.widget.DrawerLayout>

在RecycleView中加载的CardView如下所示:

&#13;
&#13;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <android.support.v7.widget.CardView
        android:id="@+id/card_view_elogs"
        card_view:cardElevation="@dimen/card_elevation"
        android:layout_gravity="center"
        android:layout_width="@dimen/card_width"
        android:layout_height="@dimen/card_height"
        android:layout_marginLeft="@dimen/card_margin_left"
        android:layout_marginTop="@dimen/card_margin_top"
        card_view:cardBackgroundColor="@color/backgroundCard"
        card_view:contentPaddingLeft="@dimen/card_content_padding_left"
        card_view:contentPaddingTop="@dimen/card_content_padding_top">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="8dp">
            <TextView
                android:text="eDriver Logs"
                android:layout_marginTop="0dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/textViewHeaderElogsCard"
                android:gravity="left"
                android:textSize="16sp"
                android:textColor="@color/cardHeader" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#333333"
                android:id="@+id/textViewBodyElogsCard"
                android:layout_gravity="center_horizontal"
                android:layout_marginLeft="4dp" />
        </LinearLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>
&#13;
&#13;
&#13; 这是MainActivity:

public class MainActivity : AppCompatActivity
{

    TypeFaceManager tfmanager;


    protected int LayoutResource
    {
        get { return Resource.Layout.activity_navigationview; }
        //get { return Resource.Layout.activity_drawerlayout; }
    }

    public Toolbar Toolbar { get; set; }

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(LayoutResource);
        Toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
        if (Toolbar != null)
        {
            SetSupportActionBar(Toolbar);

            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);
        }
        var panic = FindViewById<FloatingActionButton>(Resource.Id.panic);
        panic.Click += PanicTouched;

        RecyclerView recView = FindViewById<RecyclerView>(Resource.Id.recyclerView);

        RecyclerView.LayoutManager llm = new GridLayoutManager(this, 1, GridLayoutManager.Horizontal, false);

        recView.SetLayoutManager(llm);
        tfmanager = new TypeFaceManager(this);
        CardAdapter adapter = new CardAdapter(tfmanager.RobotoMedium);

        recView.SetAdapter(adapter);

         _drawerlayoutNav = FindViewById<DrawerLayout>(Resource.Id.DrawerLayout);

        _toolbarNav = FindViewById<Toolbar>(Resource.Id.toolbar);
        SetSupportActionBar(_toolbarNav);
        SupportActionBar.SetDisplayHomeAsUpEnabled(true);
        SupportActionBar.Title = "PeopleNet Home"; // Testing 

        // 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,
            _drawerlayoutNav, _toolbarNav,
            Resource.String.drawer_open_accessibilitySupport, Resource.String.drawer_closed_accessibilitySupport);
        _drawerlayoutNav.SetDrawerListener(drawerToggle);

        drawerToggle.SyncState();

    }

当我点击6.0设备上的工具栏时抽屉工作,但是在4.4设备上,回收者视图阻止抽屉打开。有任何想法吗?

1 个答案:

答案 0 :(得分:0)

Annnd,如果我可以阅读,根据Android设计文档,RecyclerViews属于AppBarLayout以响应可滚动事件:http://android-developers.blogspot.com.tr/2015/05/android-design-support-library.html

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/DrawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="@color/backgroundColor">
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context="PMobile_Equinox.MainActivity">

      <android.support.v7.widget.RecyclerView
          android:id="@+id/recyclerView"
          android:scrollbars="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent" />
      
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:elevation="2dp"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:minHeight="?attr/actionBarSize"
                android:background="?attr/colorPrimary" />
        </android.support.design.widget.AppBarLayout>
      <!-- the rest -->