Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java代码在android中动态创建main.xml?_Java_Android_Xml - Fatal编程技术网

如何使用java代码在android中动态创建main.xml?

如何使用java代码在android中动态创建main.xml?,java,android,xml,Java,Android,Xml,我正在尝试创建一个xml代码来动态地使用xml,而不需要xml。它只使用java代码。任何人都可以帮助我如何为这个xml内容编写Java代码。我不想在资源中使用main.xml <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/applicationframe" android:layout_width=

我正在尝试创建一个xml代码来动态地使用xml,而不需要xml。它只使用java代码。任何人都可以帮助我如何为这个xml内容编写Java代码。我不想在资源中使用main.xml

     <FrameLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/applicationframe"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFEEEEEE">
            <com.pdfplugin.QScrollView
                android:id="@+id/scrollview"
                android:layout_gravity="center"
                android:background="#FFEEEEEE"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:id="@+id/pagepane"
                    android:background="#FFEEEEEE"
                    android:gravity="center_horizontal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                </LinearLayout>
            </com.pdfplugin.QScrollView>


            <ImageView
            android:id="@+id/imgclose"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

              android:layout_gravity="top|right"
              android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:src="@drawable/readclose" />
    </FrameLayout>


为什么?您想创建一个xml还是只创建布局?是的,我将制作一个插件,但我不想在那里使用xml,我想将其与JavaCode一起使用查看并扩展代码。据我所知,您无法在运行时创建xml文件并将其用作资源。原因很明显:如果您使用ID,ID应该包含在生成的R文件中,该文件在运行时不能修改…@WarrenFaith您可以使用标记并避免ID问题。但是正如您已经说过的,您不能使用自己创建的xml文件,因为android会预处理xml布局文件。