动态添加删除控制表单linearlayout

AMH*_*AMH 5 android android-linearlayout

我有3个布局,我需要点击按钮访问某些布局和广告从中删除控件任何想法如何实现,这是我使用的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.20"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/backbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Back" />

        <Button
            android:id="@+id/backbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="next" />
    </LinearLayout>
    <!-- the two columns part -->

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.80"
        android:orientation="horizontal" >

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="0.80" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="First Name" />
        </LinearLayout>

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="0.20" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="second Name" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

K_A*_*nas 20

在Android上从父级删除视图:

View myView = findViewById(R.id.my_view);
ViewGroup parent = (ViewGroup) myView.getParent();
parent.removeView(myView);
Run Code Online (Sandbox Code Playgroud)

Android删除所有子视图:

LinearLayout formLayout = (LinearLayout)findViewById(R.id.formLayout);
formLayout.removeAllViews();
Run Code Online (Sandbox Code Playgroud)

在Android上向父级添加视图:

Button myButton = new Button(getApplicationContext());
myButton.setLayoutParameters(new LinearLayout.LayoutParams(
                                     LinearLayout.LayoutParams.FILL_PARENT,
                                     LinearLayout.LayoutParams.FILL_PARENT));

myLayout.addView(myButton);
Run Code Online (Sandbox Code Playgroud)

您可以使用:

LinearLayout.LayoutParams.FILL_PARENT
Run Code Online (Sandbox Code Playgroud)

要么

LinearLayout.LayoutParams.WRAP_CONTENT
Run Code Online (Sandbox Code Playgroud)