Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.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 回收视图';添加项目时,s滚动到顶部_Android_Android Recyclerview - Fatal编程技术网

Android 回收视图';添加项目时,s滚动到顶部

Android 回收视图';添加项目时,s滚动到顶部,android,android-recyclerview,Android,Android Recyclerview,我有一个RecyclerView,我使用顶部填充,当我从网络获取数据并将其添加到适配器时,它最初会显示,RecyclerView滚动到顶部,填充更改为零 在添加新项目时,有没有办法保持顶部填充 Xml布局: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content

我有一个
RecyclerView
,我使用顶部填充,当我从网络获取数据并将其添加到适配器时,它最初会显示,
RecyclerView
滚动到顶部,填充更改为零

在添加新项目时,有没有办法保持顶部填充

Xml布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:background="@color/main_bg" android:clickable="true">

<FrameLayout
    android:layout_width="match_parent" android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/iv_profile_cover"
        android:scaleType="fitXY"
        android:layout_width="match_parent" android:layout_height="@dimen/profile_cover_height"
        android:contentDescription="Cover image" />

    <ImageView
        android:src="@color/light_grey_with_alpha"
        android:contentDescription="Gray Overlay"
        android:layout_width="match_parent" android:layout_height="@dimen/profile_cover_height" />

</FrameLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/rv_profile_photo_list"
    android:clipToPadding="false" android:clipChildren="false" android:paddingTop="@dimen/profile_content_height"
    android:layout_marginTop="?attr/actionBarSize"
    android:layout_marginLeft="16dp" android:layout_marginRight="16dp"
    android:layout_width="match_parent" android:layout_height="wrap_content" />

</FrameLayout>


您可以发布版面和您正在使用的代码吗?我已经为版面添加了代码。您还需要适配器的代码吗?请尝试将rrot布局从FrameLayout替换为RelativeLayout,将第二个FrameLayout替换为LinearLayout,并回复Backsees调用notifyItemInserted()时出错,只要我将其更改为
notifyDataSetChanged()
以上所述的问题就消失了。谢谢你愿意帮忙!:)notifyItemInserted是基于位置的。。。很好,你解决了它