Android 如何正确使用recyclerview和include布局?
我想创建一个新闻提要列表,比如简单的twitter。我在谷歌上搜索了一下,建议使用recyclerview。但在我的例子中,我已经在我的主要活动布局中使用了include视图。我试图修改我的代码,但总是出错。这是我的密码 activty_master.xmlAndroid 如何正确使用recyclerview和include布局?,android,android-recyclerview,navigation-drawer,Android,Android Recyclerview,Navigation Drawer,我想创建一个新闻提要列表,比如简单的twitter。我在谷歌上搜索了一下,建议使用recyclerview。但在我的例子中,我已经在我的主要活动布局中使用了include视图。我试图修改我的代码,但总是出错。这是我的密码 activty_master.xml <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schema
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
android:id="@+id/layout_include"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/app_bar_master" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/activity_master_drawer" />
</android.support.v4.widget.DrawerLayout>
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.bangun.halo.MasterActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<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/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include
android:id="@+id/layout_content"
layout="@layout/content_master"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email"
android:visibility="gone"/>
</android.support.design.widget.CoordinatorLayout>
代码始终在以下位置终止:
FrameLayout layoutInclude=FrameLayoutfindViewByIdR.id.layout\u include//当执行setupRecyclerview步骤时,应用程序始终在此终止
如何解决这个案子?
如何正确使用recyclerview和include布局
如果我的问题仍然缺乏信息,我会给出更多。
请尝试使用协调器布局而不是框架
CoordinatorLayout layoutInclude = (CoordinatorLayout)findViewById(R.id.layout_include); //application always terminated here
CoordinatorLayout layoutInclude = (CoordinatorLayout)findViewById(R.id.layout_include); //application always terminated here