Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android RecyclerView不渲染高度为0dp的单元格_Android_Android Recyclerview - Fatal编程技术网

Android RecyclerView不渲染高度为0dp的单元格

Android RecyclerView不渲染高度为0dp的单元格,android,android-recyclerview,Android,Android Recyclerview,我制作了一个应用程序,具有入职流程。 我的MainActivity类中有一个recyclerview,我想在onResume点击时更新它(就在入职流程之后)。 这就是回收器xml的外观: <android.support.v7.widget.RecyclerView android:id="@+id/notifyRecycler" android:layout_width="0dp" android:layout_height="230dp"

我制作了一个应用程序,具有入职流程。 我的MainActivity类中有一个recyclerview,我想在onResume点击时更新它(就在入职流程之后)。 这就是回收器xml的外观:

<android.support.v7.widget.RecyclerView
        android:id="@+id/notifyRecycler"
        android:layout_width="0dp"
        android:layout_height="230dp"
        android:clipToPadding="false"
        android:orientation="horizontal"
        app:layoutManager="android.support.v7.widget.LinearLayoutManager"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

这就是单元布局:

    <android.support.constraint.ConstraintLayout 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/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/cardDetails"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

</...>

我用clear和add交换适配器中的数据,当我将单元格布局视图高度从0dp更改为与父级匹配时,一切都很好。 它也适用于从oncreate首次运行,但当我尝试从onResume更新时,它不会通知数据集已更改。 以下是从onResume函数调用的适配器代码:

public void setNewData(ArrayList<Model> models) {
    this.notifications.clear();
    this.notifications.addAll(models);
    notifyDataSetChanged();
}
public void setNewData(ArrayList模型){
this.notifications.clear();
this.notifications.addAll(模型);
notifyDataSetChanged();
}
在onCreate中:

adapter = new NotificationsAdapter(new ArrayList<>(), this);
notifyRecycler.setAdapter(adapter);
adapter=newnotificationsadapter(newarraylist(),this);
notifyRecycler.setAdapter(适配器);
在onResume中,我使用boolan var使其仅在恢复应用程序时更新:

ArrayList<NotificationModel> notificationsList = new ArrayList<>();
    notificationsList.add(...);
    notificationsList.add(...);

    adapter.setNewData(notificationsList);
ArrayList notificationsList=new ArrayList();
通知列表添加(…);
通知列表添加(…);
adapter.setNewData(notificationsList);

通过将父视图组从ConstraintsLayout更改为RelativeLayout来解决此问题。

能否共享onCreate和onResume的代码?您如何认识到onResume未通知数据集已更改,从onResume传递的数据集与从onCreate传递的数据集不同吗?是的,它只是一个硬编码的数据集,并将其传递给setNewData方法。如果从onCreate和onResume方法传递相同的数据集,则无法注意到第二次调用是否通知了数据集更改。请提供onCreate和onResume方法调用以及要传递给setNewData方法的数据集。更新了每次onCreate和onResume的postAs代码,听起来不应该有任何问题。告诉我你到底遇到了什么问题。通过查看代码,我可以看到您在列表notificationsList中设置的任何项目,这些项目应该能够正确显示。