Android 不使用充气机和回收器查看什么';在代码中重新创建xml的最佳方法是什么?

Android 不使用充气机和回收器查看什么';在代码中重新创建xml的最佳方法是什么?,android,button,layout,view,Android,Button,Layout,View,当按下切换按钮时,我想在切换按钮下显示这个 然后当再次按下切换按钮时消失,我已经查看了可扩展列表视图,但对于一些视觉上不会改变的项目来说,它似乎过于复杂 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height=

当按下切换按钮时,我想在切换按钮下显示这个 然后当再次按下切换按钮时消失,我已经查看了可扩展列表视图,但对于一些视觉上不会改变的项目来说,它似乎过于复杂

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:textSize="40dp"
        android:id="@+id/button"
        android:text="Dummy Job"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

   <!-- <android.support.v7.widget.RecyclerView
        android:id="@+id/jobStats"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


    </android.support.v7.widget.RecyclerView> -->

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:text="New Text"
        android:id="@+id/viewMachine" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:text="New Text"
        android:id="@+id/viewItem"  />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:text="New Text"
        android:id="@+id/viewDate"  />
    <LinearLayout
        android:id="@+id/testing"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="40dp"
            android:text="Button"
            android:id="@+id/bJobOpen"
            android:layout_weight="1" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="40dp"
            android:text="Button"
            android:id="@+id/bJobEdit"
            android:layout_weight="1" />

        <Button
            android:layout_width="245dp"
            android:layout_height="wrap_content"
            android:text="Button"
            android:id="@+id/bJobExport"
            android:textSize="40dp"
            android:layout_weight="1" />
    </LinearLayout>
</LinearLayout>
问题是当我创建它时,它看起来是这样的


将视图设置为Invi建议直接在应用程序中使用此库

 LinearLayout layout = (LinearLayout) findViewById(R.id.ReportsLayout);
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f);
                //layout.setLayoutParams(lp);
                //layout.setLayoutParams(lp);
                //layout.setOrientation(LinearLayout.HORIZONTAL);
                TextView viewMachine = new TextView(Reports.this);
                TextView viewItem = new TextView(Reports.this);
                TextView viewDate = new TextView(Reports.this);
                LinearLayout horLayout = new LinearLayout(context);
                Button enterJob = new Button(Reports.this);
                Button editJob = new Button(Reports.this);
                Button exportJob = new Button(Reports.this);
                //enterJob.setLayoutParams(lp);
                //editJob.setLayoutParams(lp);
                //exportJob.setLayoutParams(lp);
               if( button.isChecked()==(true)) {
                   layout.addView(viewMachine,lp);
                   layout.addView(viewItem,lp);
                   layout.addView(viewDate,lp);

                   layout.addView(enterJob,lp);
                   layout.addView(editJob, lp);
                   layout.addView(exportJob, lp);
               }
                else{
                    //layout.setVisibility(View.INVISIBLE);
                }
            }
        };
    }