【发布时间】:2019-08-26 21:37:39
【问题描述】:
我的数据库中有一份食谱列表。每个食谱都包含一个标题和一个成分列表,如下所示:
这需要在一个 android 设备的 recyclerview 中正确显示。到目前为止,在我的 activity_main.xml 中,我创建了一个 recyclerview:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:padding="20dp"
android:background="#f1f1f1"
android:gravity="center">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewRecipes"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
自定义recyclerview列表项如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_margin="20dp"
android:background="@drawable/cornered_background"
android:padding="20dp">
<TextView
android:id="@+id/tvRecipeTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textColor="@android:color/black">
<ImageView
android:id="@+id/imgDelete"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/delete"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewIngredients"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:minHeight="100dp"
android:layout_below="@id/tvRecipeTitle">
</android.support.v7.widget.RecyclerView>
<ImageView
android:id="@+id/imgEdit"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/edit"
android:layout_marginTop="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
正如您从上面的代码中看到的那样,我对每个配方项目中的各种成分都有另一个回收视图。我相信这不是解决这个问题的正确方法。如何有效地显示每个 recyclerview 项目中的成分列表?
【问题讨论】:
-
你试过Chip component。我不确定它是否是
AdapterView看看。 -
我觉得不走材料设计就好了/
标签: java android android-recyclerview