2013-07-19 43 views
-5

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

我该怎么做?

+0

[我试图以编程方式插入WebView到我的代码]的可能重复(http://stackoverflow.com/questions/13815027/im-trying-to-programmatically-insert-a-webview-into-my-code ) – Ranco

+0

你会让你的问题更具体吗? – srain

回答

0

你必须给一个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); 

,现在您可以您的WebView添加到此布局。