这是我的main.xml文件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, MainActivity"
/>
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/urlContainer" />
</LinearLayout>
这是我的java文件。
package szdf.asdf;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends Activity
{
private WebView webView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.webView);
String customHtml = "<html><body><h1>Hello, WebView</h1>" +
"<h1>Heading 1</h1><p>This is a sample paragraph.</p>" +
"</body></html>";
webView.loadData(customHtml, "text/html", "UTF-8");
}
}
我试图添加一个webview到我的应用程序,但它编译错误
错误:错误:没有找到与给定名称匹配的资源(在'layout_below',值'@id/urlContainer')。
谁能告诉我我的代码有什么问题?
android:layout_below="@id/urlContainer" />
你没有这个ID的资源,删除它:)
您引用的对象具有android:layout_below
属性上不存在的ID。删除行或添加一个ID为@id/urlContainer的项。
没有id为urlContainer
的资源容器。所以删除这一行:
android:layout_below="@id/urlContainer" />