RelativeLayout layout = findViewById(R.id.relativeLayout); layout.removeAllViews();
RelativeLayout layout = new RelativeLayout(this); layout.addView(childView1); layout.addView(childView2); layout.addView(childView3); layout.removeAllViews();In this example, the layout variable refers to a newly created RelativeLayout. Three child views are added to the layout using the addView method. The removeAllViews method removes all three child views from the layout. Package Library: android.widget