我有大约70个XML布局文件要在一个活动中膨胀(就像一个输入字段列表。就像一些巨大的形式)。加载大约需要3-4秒。我无法使用RecyclerView,因为它在打开键盘时崩溃。此外,上下滑动速度也很慢)
请建议一些快速打开活动的方法。
发布于 2018-06-05 19:39:06
对于那些面临类似问题的人,我找到了一个解决方案:我使用了AsyncTask (其中膨胀部分在后台完成,只是添加视图在前台完成)
public class MyAsync extends AsyncTask<Void, View, Void> {
LayoutInflater inflater;
Activity activity;
LinearLayout parent;
List<Integer> layoutIds;
public MyAsync(Activity activity,LinearLayout linLayout,List<Integer> layoutIds) {
this.activity = activity;
this.parent = linLayout;
this.layoutIds = layoutIds;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
inflater = activity.getLayoutInflater();
}
@Override
protected Void doInBackground(Void... voids) {
for (int i = 0; i < layoutIds.size(); i++) {
View view = inflater.inflate(layoutIds.get(i), null);
publishProgress(view);
}
return null;
}
@Override
protected void onProgressUpdate(View... view) {
super.onProgressUpdate(view);
parent.addView(view[0]);
}
}https://stackoverflow.com/questions/50681614
复制相似问题