AsyncLayoutInflater

2021-01-01  本文已影响0人  CentForever
if(!isAsyncOn) {
                LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View view = inflater.inflate(R.layout.layout_dummy, null);
                LinearLayout inflatedLayout = (LinearLayout) view.findViewById(R.id.layout_dummy);
                parentLayout.addView(inflatedLayout);
            }else {
                AsyncLayoutInflater asyncInflator = new AsyncLayoutInflater(this);
                asyncInflator.inflate(R.layout.layout_dummy, null, new AsyncLayoutInflater.OnInflateFinishedListener() {
                    @Override
                    public void onInflateFinished(View view, int resid, ViewGroup parent) {
                        LinearLayout inflatedLayout = (LinearLayout) view.findViewById(R.id.layout_dummy);
                        parentLayout.addView(inflatedLayout);
                    }
                });
            }
        }

https://proandroiddev.com/asynclayoutinflater-on-the-way-to-the-ui-thread-to-be-responsive-743cb6cb201

上一篇下一篇

猜你喜欢

热点阅读