【问题标题】:RecyclerView Scrolling SlowRecyclerView 滚动缓慢
【发布时间】:2019-10-31 10:12:27
【问题描述】:

当我从 Json 获取数据并放入 recyclerview 时。它滚动得很慢?请帮我解决这个问题。

recyclerView = findViewById(R.id.recycleview);
            adapter1 = new Landing_recycler_adapter(MainActivity.this, movieList);
            GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(),2);
            gridLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); // set Horizontal Orientation
            recyclerView.setLayoutManager(gridLayoutManager); // set LayoutManager to RecyclerView
    //        recyclerView.setLayoutManager(new GridLayoutManager(this, GridLayoutManager.HORIZONTAL, true));


            recyclerView.setHasFixedSize(true);
            recyclerView.setAdapter(adapter1);

            getJsonData();

【问题讨论】:

  • 你为什么要设置layoutmanager两次?
  • @sanjeev 一行在评论 LOL 下 :)
  • 很高兴您编辑了这篇文章。你在 recyclerview 之外使用滚动视图吗?
  • 2.设置适配器后得到getJsonData();? 3.movi​​eList包含什么? P.S 请提供更多代码..
  • 我没有得到确切的答案。

标签: android json android-recyclerview nestedrecyclerview


【解决方案1】:

使用这个

            getJsonData();
            recyclerView = findViewById(R.id.recycleview);
            adapter1 = new Landing_recycler_adapter(MainActivity.this, movieList);

            recyclerView.setLayoutManager(new LinearLayoutManager(this));
            recyclerView.setAdapter(adapter1);

            getJsonData();
            recyclerView = findViewById(R.id.recycleview);
            adapter1 = new Landing_recycler_adapter(MainActivity.this, movieList);

            recyclerView.setLayoutManager(new GridLayoutManager(this,2));
            recyclerView.setAdapter(adapter1);

【讨论】:

  • 无 Logcate 错误。只是recyclerview慢慢移动。表示性能很差。
【解决方案2】:

同时禁用 RecyclerView 的嵌套滚动

recyclerView.setNestedScrollingEnabled(false);

【讨论】:

  • 请提供更多代码,此问题可能与其他操作有关。
  • 无 Logcate 错误。只是recyclerview慢慢移动。表示性能很差。
  • 如果你在recyclerView的item view中设置image到imageView,那么就用Glide或者Picasso来做吧。
猜你喜欢
  • 2021-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多