使用自定义视图填充非常长的线性布局,非常慢

Populating very long linear layout with custom views, extremely slow

我正在尝试使用图片中的自定义视图列表填充线性布局:

为此,我在新的 View 对象中膨胀 foo.xml,然后使用 .setText 更改文本视图,然后将新的 View 添加到线性布局中。

问题是:它非常慢,即使在模拟器之外,在我的 S9 中也需要 10 多秒才能显示。

LinearLayout layout = findViewById(R.id.layout);

while(a<500){
    Person person = new Person();

    View personData = inflater.inflate(R.layout.person, layout, false);
    layout.addView(personData);
    ((TextView) coinData.findViewById(R.id.textView_text_name)).setText(person.name);

    a=a+1
}

编辑:谢谢你们!我现在就试试 RecyclerView

要创建列表,请使用 RecyclerView,它只是传统 ListView 的高级版本

您可以按照 Recycler View 教程进行操作 Here.