Recyclerview覆盖工具栏

时间:2015-07-02 11:14:48

标签: android overlay android-recyclerview

我使用新的com.android.support:design:22.2.0库。当recyclerview初始化它覆盖工具栏时。我认为这是因为初始化recyclelerview不正确。我尝试在单个文件中插入recyclerview,但我无法理解如何对其进行充气

 super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final ActionBar ab = getSupportActionBar();
    if (ab != null) {
       ab.setHomeAsUpIndicator(R.drawable.menu_and);
       ab.setDisplayHomeAsUpEnabled(true);
       }
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
    setupDrawerContent(navigationView);
    }
    lNews.clear();
    populatedata();
    mLinearLayoutManager = new LinearLayoutManager(getApplicationContext());
    mRecyclerView = (RecyclerView)findViewById(R.id.recycleralda);
    mRecyclerView.setLayoutManager(mLinearLayoutManager);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerviewAdapter = new RecyclerViewAdapter(getApplicationContext());
    mRecyclerviewAdapter.loadNews(lNews);
    mRecyclerView.setAdapter(mRecyclerviewAdapter);

home.xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/drawer_layout"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:fitsSystemWindows="true">
        <include layout="@layout/app_bar"/>
            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycleralda"
                android:layout_below="@+id/app_bar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                xmlns:android="http://schemas.android.com/apk/res/android">
            </android.support.v7.widget.RecyclerView>

        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_height="match_parent"
            android:layout_width="wrap_content"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header"
            app:menu="@menu/drawer_view"/>  
    </android.support.v4.widget.DrawerLayout>

app_bar.xml

    <?xml version="1.0" encoding="utf-8"?>
        <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            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_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_scrollFlags="scroll|enterAlways"
                />
        </android.support.design.widget.AppBarLayout>
    </android.support.design.widget.CoordinatorLayout>

请上传img   http://i.stack.imgur.com/LxcJF.jpg

1 个答案:

答案 0 :(得分:2)

在app_bar.xml文件中添加RecyclerView 在跟随

之前
 </android.support.design.widget.CoordinatorLayout>

以及后续行

</android.support.design.widget.AppBarLayout>