我正在尝试使用已刻录数据的列表制作一个recyclerview,但是在测试时,滚动条和整个屏幕都太滞后了,我已经尝试不填充列表并且该屏幕可以正常工作,但是我有另一个屏幕在这里,我还填写了一个平等的清单,其中包括布局中的更多内容,这没有问题。
这是我的代码:
TextView txtToolbar;
RecyclerView list_comercio;
ComercioAdapter comercioAdapter;
List<Comercio> comercioList;
String categoria;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_comercio);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
toolbar.setNavigationIcon(R.drawable.back);
Window window = ComercioActivity.this.getWindow();
window.setStatusBarColor(getResources().getColor(R.color.colorPrimary));
categoria = getIntent().getStringExtra("cat");
txtToolbar = findViewById(R.id.txtToolbar);
txtToolbar.setText(categoria);
list_comercio = findViewById(R.id.listComercios);
comercioList = new ArrayList<>();
comercioList.add(new Comercio(0, "Odontología", R.drawable.dent));
comercioList.add(new Comercio(1,"Fútbol", R.drawable.futbol));
comercioList.add(new Comercio(2, "Peluquería", R.drawable.peluqueria));
comercioList.add(new Comercio(3, "Peluquería", R.drawable.peluqueria));
comercioList.add(new Comercio(4, "Peluquería", R.drawable.peluqueria));
comercioList.add(new Comercio(5, "Peluquería", R.drawable.peluqueria));
comercioList.add(new Comercio(6, "Peluquería", R.drawable.peluqueria));
comercioList.add(new Comercio(7, "Peluquería", R.drawable.peluqueria));
list_comercio.setHasFixedSize(true);
list_comercio.setLayoutManager(new LinearLayoutManager(this));
comercioAdapter = new ComercioAdapter(this, comercioList, this);
list_comercio.setAdapter(comercioAdapter);
}
如果您在RecyclerView
中使用ScrollView
,请使用NestedScrollView
并将setNestedScrollingEnabled = false
标记为RecyclerView
。