Circular dependencies are not allowed in RelativeLayout
From the shared error, you can not modify the inner existed control of the RelativeLayout. That means you only can add View from outside of the Root RelativeLayout.
For example , create another_layout.xml as follows, and it only contains a Control. You could modify it with your needs control.
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/AnotherRootView"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:text="AnotherListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/AnotherListView" />
</LinearLayout>
Now back to Root RelativeLayout, and add android:id="@+id/RootView"
in its xml.
Then we can add another_layout.xml
in Root RelativeLayout as follows:
private void Change_Click(object sender, System.EventArgs e)
{
// get root view
RelativeLayout rootView = (RelativeLayout)FindViewById<RelativeLayout>(Resource.Id.RootView);
// set layout params
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(WindowManagerLayoutParams.MatchParent, WindowManagerLayoutParams.WrapContent);
layoutParams.AddRule(LayoutRules.Below, video.Id);
// get another layout
LayoutInflater inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
LinearLayout linearLayout = (LinearLayout)inflater.Inflate(Resource.Layout.another_layout, null,true);
// get and set data for anther list view
ListView anotherListView = (ListView)linearLayout.FindViewById(Resource.Id.AnotherListView);
// we can remove the previous list view
rootView.RemoveView(audiolist);
// add another list view which inside the anther layout
rootView.AddView(linearLayout, layoutParams);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…