我想在 RecyclerView 中显示一个 fragment 作为第一个项目,我可以这样做吗?
最佳答案
我不确定,但我认为这是可能的。
当您为 RecyclerView
或 ListView
创建一个 row_layout.xml
时,而不是在其中添加任何其他布局;你应该在那里保留一个 fragment ,而那个 fragment 又会有你的 row_layout.xml
例子:
你的 row_layout.xml
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout="@layout/your_layout"
android:name="packageName.className"
tools:layout="@layout/your_layout"
android:id="@+id/navigation_fragment" />
fragment 布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/your_id"
tools:context="packageName.className">
<!--Any view inside-->
</LinearLayout>
关于android - 可以将 fragment 放入 RecyclerView 或 ListView 中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33413648/