我有一個協調器布局與回收器視圖,我想以程式設計方式添加。其程式添加的原因是因為擴充協調器布局的不同碎片可能會使用不同類型的回收利用。
通常對于回收器視圖,為了設定此行為,我将其添加到xml:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
工作正常但是,當我以程式設計方式建立回收器視圖,然後将它們添加到framelayout時,我完全失去了如何添加此行為:
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:id="@+id/coordLayout"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".MainActivity">
android:fitsSystemWindows="true" android:layout_height="@dimen/app_bar_height"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
android:fitsSystemWindows="true" android:layout_width="match_parent"
android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary">
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">