Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.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
Android通过代码获取布局_Android - Fatal编程技术网

Android通过代码获取布局

Android通过代码获取布局,android,Android,我在android的布局文件夹中有一个xml布局文件。 我想通过代码引用该文件来添加webview 我该怎么做?您必须为布局提供一个id: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_h

我在android的布局文件夹中有一个xml布局文件。 我想通过代码引用该文件来添加webview


我该怎么做?

您必须为布局提供一个id:

<?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="fill_parent"
    android:orientation="vertical"
    id="@+id/layout" >

</LinearLayout>

现在,您可以将您的网络视图添加到此布局。

可能的重复项会使您的问题更加具体吗?
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);