【问题标题】:It's possible to put a fragment into a RecyclerView or ListView?可以将片段放入 RecyclerView 或 ListView 吗?
【发布时间】:2015-10-29 12:00:00
【问题描述】:

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

【问题讨论】:

  • 你可以给recyclerview或者listview添加一个header
  • @MalekHijazi 似乎没有recyclerview的标题。有什么例子或参考资料吗?
  • 是的,您可能必须在适配器中执行此操作。如果您还没有弄清楚,请告诉我为您指明正确的方向

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


【解决方案1】:

我不确定,但我认为这是可能的。 当您为RecyclerViewListView 创建row_layout.xml 时,而不是在其中添加任何其他布局;你应该在那里保留一个片段,然后那个片段将拥有你的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" />

片段布局

<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>

【讨论】:

  • 我可以使用layoutinflater给fragment_layout.xml充气吗?我知道 Fragment 与其他通常被夸大的 View 不同。
猜你喜欢
  • 2012-07-06
  • 1970-01-01
  • 2019-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多