Android 网络视图大小始终为0
我似乎无法显示我的WebView。我怀疑是因为它的尺寸是0。我不知道如何取消此网络视图的零 这是我的布局:Android 网络视图大小始终为0,android,android-webview,Android,Android Webview,我似乎无法显示我的WebView。我怀疑是因为它的尺寸是0。我不知道如何取消此网络视图的零 这是我的布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <WebView android:i
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
通过使用
Activity.setContentView()
将布局附加到应用程序窗口,您正在扩展布局,但从未显示它。使用其中一个
View webViewLayout = ((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.twitterfeed, null, false);
setContentView(webViewLayout);
WebView webView = (WebView) webViewLayout.findViewById(R.id.webView1);
或者更简单地说,让框架为您实现通胀:
setContentView(R.layout.twitterfeed);
WebView webView = (WebView) findViewById(R.id.webView1);
- 您需要使用ViewTreeObserver来测量webview布局的宽度和高度
- ViewTreeObserver触发它的全局布局侦听器,并有自己的线程来测量布局维度
webView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { System.out.println("webView: " + webView.getWidth()); System.out.println("webView: " + webView.getHeight()); } });
java.lang.RuntimeException:您的内容必须具有id属性为“android.R.id.list”的ListView
。这似乎很奇怪。为什么我必须有一个ListView?您正在扩展ListActivity
。将其更改为常规活动
。
webView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
System.out.println("webView: " + webView.getWidth());
System.out.println("webView: " + webView.getHeight());
}
});