【发布时间】:2020-06-27 21:35:42
【问题描述】:
我有一个导航抽屉活动,其中包含一个包含 RecyclerView 的片段。如果此 RecyclerView 是此片段中的唯一组件,则它可以完美运行,但我想在 RecyclerView 上方添加一个按钮,因此将 RecyclerView 和按钮插入到 LinearLayout 中。但随后 RecyclerView 已经消失或不再显示任何元素。
如何将此 RecyclerView 嵌入到布局中?
RecyclerView 与这个一起工作:
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
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/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:name="com.company.myapp.ui.ItemFragment"
app:layoutManager="LinearLayoutManager"
tools:context=".ui.home.HomeFragment"
tools:listitem="@layout/fragment_item" />
RecyclerView 已经在这个消失了:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete Item" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:name="com.company.myapp.ui.ItemFragment"
app:layoutManager="LinearLayoutManager"
tools:context=".ui.home.HomeFragment"
tools:listitem="@layout/fragment_item" />
</LinearLayout>
在此处查看完整项目:https://github.com/jriegraf/MyApp
【问题讨论】:
标签: java android android-layout android-recyclerview