dependencies { implementation 'androidx.asynclayoutinflater:asynclayoutinflater:1.0.0' } <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World!" /> <ProgressBar android:id="@+id/progressBar" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> AsyncLayoutInflater inflater = new AsyncLayoutInflater(context); inflater.inflate(R.layout.activity_main, null, new AsyncLayoutInflater.OnInflateFinishedListener() { @Override public void onInflateFinished(View view, int resid, ViewGroup parent) { TextView textView = view.findViewById(R.id.textView); ProgressBar progressBar = view.findViewById(R.id.progressBar); textView.setText("Hello Async Layout Inflater!"); progressBar.setVisibility(View.GONE); parent.addView(view); } });


上一篇:
下一篇:
切换中文