小编AAA*_*AAA的帖子

如何停止刷新recyclerview数据每次滚动到顶部位置android

我正在尝试使用 recyclerview 制作类似于视频的布局。我制作了一个 recyclerview,它会在一定时间间隔后更新列表,但问题是数据更新后它会自动滚动到顶部位置。我想做一些像视频一样的东西。https://youtu.be/omcS-6LeKoo 我尝试过使用来自 SO RecyclerView 的链接,当更改适配器数据时 RecyclerView notificationDataSetChanged 滚动到顶部位置但无法解决。下面是我的尝试

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        recyclerView = findViewById(R.id.recyclerViewId);

        handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
//                Toast.makeText(getApplicationContext(),"Updating",Toast.LENGTH_LONG).show();
                listShow();
                handler.postDelayed(this,1000);

            }
        },1000);

    }

void listShow(){

        retrofitApiCall = RetrofitInstance.getRetrofitInstance().create(RetrofitApiCall.class);
        Call<ModelClass_JSONParse> getDetails = retrofitApiCall;
        anime = ExtendedAnime.getAll();

        getDetails.enqueue(new Callback<ModelClass_JSONParse>() {
            @Override
            public void onResponse(Call<ModelClass_JSONParse> call, 
         Response<ModelClass_JSONParse> response) {
                Log.v("Res",response.toString());
                getWithValues = new HashMap<>();

                if (response.isSuccessful()){

                        list.add(mModelClass_adapter);
                    }
                    adapter = new Adapter(getApplicationContext(),list);
                    StaggeredGridLayoutManager …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

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

为什么在 android recyclerview 中两行(消息)之间有这么大的空间

在此输入图像描述

我面临两个问题。为什么 recyclerview 中的两行(消息)之间的空间太大。我正在尝试通过 recyclerview 制作一个聊天应用程序。为什么进入活动时消息没有出现,而是在单击消息编辑文本时出现消息。

我的代码:

我自己的聊天布局:

<TextView
    android:id="@+id/message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_marginRight="10dp"
    android:textIsSelectable="true"
    android:background="@drawable/bg_bubble_gray"
    android:textSize="14dp" />

<TextView
    android:id="@+id/timestamp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@id/message"
    android:layout_below="@id/message"
    android:layout_marginBottom="25dp"
    android:padding="10dp"
    android:textSize="10dp" />
Run Code Online (Sandbox Code Playgroud)

chat layout myself:



 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:paddingTop="5dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        >

        <TextView
            android:id="@+id/message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="10dp"
            android:textIsSelectable="true"
            android:background="@drawable/bg_bubble_white"
            android:textSize="14dp" />

        <TextView
            android:id="@+id/timestamp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/message"
            android:layout_marginBottom="25dp"
            android:layout_marginLeft="10dp"
            android:paddingLeft="10dp"
            android:paddingTop="6dp"
            android:textSize="10dp" />

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

适配器:

public class ChatRoomThreadAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

private static String TAG = ChatRoomThreadAdapter.class.getSimpleName();

private String …
Run Code Online (Sandbox Code Playgroud)

android adapter android-recyclerview

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

标签 统计

android ×2

android-recyclerview ×2

adapter ×1