小编Gab*_*ias的帖子

recyclerview将数据添加到顶部而不会搞乱滚动?

我正在尝试在recyclerview中的滚动顶部添加一些日期.它是工作,除了滚动,当添加一些新数据时,它会搞乱一切.

我看到了这个主题:

链接1

链接2

但他们都没有解决我的问题.

也许有人可以帮我这个...

我使用排球得到一些数据,如下:

try {
                //Getting json
                json = array.getJSONObject(i);

                //Adding data to the object
                PostObj.setImageUrl(json.getString(Config.TAG_PPIC));
                ...


            } catch (JSONException e) {
                e.printStackTrace();
            }
            //Adding object to the list
            listLf.add(0, PostObj); //0, postobj
        }

        //Notifying the adapter that data has been added or changed
        //adapter.notifyDataSetChanged(); the scroll will jump to position 0
        adapter.notifyItemRangeChanged(0, adapter.getItemCount()); // still not working
    }
Run Code Online (Sandbox Code Playgroud)

我试图添加adapter.notifyItemRangeChanged(0, adapter.getItemCount());但仍然是相同的东西.

我也尝试过:

// Save state
private Parcelable recyclerViewState;
recyclerViewState = recyclerView.getLayoutManager().onSaveInstanceState();

// Restore state …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-recyclerview

5
推荐指数
1
解决办法
789
查看次数

css在图像前对齐文本

我在它前面有一个图像和一个文本。问题是,我无法对齐文本和图像,文本总是在底部,我希望它在图像的中间前面。

这是问题所在:

    .imgf{
     width:45px;
    }
    .textf{
     margin-left:2px;
    }
Run Code Online (Sandbox Code Playgroud)
<img src=https://upload.wikimedia.org/wikipedia/commons/thumb/e/e3/Nuvola_wikipedia_icon.png/240px-Nuvola_wikipedia_icon.png class=imgf> <span class=textf>comments(20)</span>
Run Code Online (Sandbox Code Playgroud)

html css vertical-alignment

1
推荐指数
1
解决办法
4957
查看次数

ScrollView慢速滚动且项目消失

我正在尝试添加ScrollView来保存标头和RecyclerView。

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

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

    <RelativeLayout
        android:id="@+id/profile"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="?attr/colorPrimary">

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:id="@+id/imageView"
            android:adjustViewBounds="true"
            android:cropToPadding="false" />


    </RelativeLayout>


    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:scrollbars="none"
        android:layout_alignParentLeft="true" />


    </RelativeLayout>

</ScrollView>
Run Code Online (Sandbox Code Playgroud)

但是我有两个问题尝试这样做:

  • 相对布局ID /配置文件正在消失。当我打开活动时,它会显示1秒钟,然后消失。

  • RecyclerView滚动太慢。

有任何想法吗?

android android-layout android-xml android-scrollview android-recyclerview

0
推荐指数
1
解决办法
885
查看次数