android - 可以将 fragment 放入 RecyclerView 或 ListView 中吗?

标签 android android-fragments android-listview android-recyclerview

我想在 RecyclerView 中显示一个 fragment 作为第一个项目,我可以这样做吗?

最佳答案

我不确定,但我认为这是可能的。 当您为 RecyclerViewListView 创建一个 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/

相关文章:

Android - 确定短信发送失败的原因

android - 设计支持 TabLayout

java - Android - 如何结束 fragment

android - 在 fragment 中显示可点击列表

java - 错误: Context cannot be converted to Executor

android - adapter 的内容发生了变化但是 ListView 没有收到通知,后台没有更新

android - 捕获 ListView 屏幕

android - 每次滚动时都会调用 CustomAdapter getView()

javascript - 如何在 webView 中启用 javascript

android - 如何减少在冷启动时启动应用程序所需的时间