第一次布局后无法获取viewWidth(ViewPager中的WebView)
稍后我将更新有关如何在 ViewPager
中实现 WebView
的完整教程,但我遇到了一个非常奇怪的问题,我不知道如何解决。
以下是我正在运行的实现...
XML:
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/lastLoginText"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_below="@+id/PreferencesButton" >
</android.support.v4.view.ViewPager>
ViewPager 实例化对象:
((ViewPager) collection).removeAllViews();
WebView a = webview[position];
((ViewPager) collection).addView(a);
Webviews 在单独的 (InitWebViews) 中设置
webview[0] = new WebView(this.getApplicationContext());
webview[0].loadUrl("file:///android_asset/test.html");
webview[1] = new WebView(this.getApplicationContext());
webview[1].loadUrl("file:///android_asset/test.html");
webview[2] = new WebView(this.getApplicationContext());
webview[2].loadUrl("file:///android_asset/test.html");
任何想法为什么会这样,或者我如何强制 viewWidth
1280?或者我初始化 WebView 的方式是否还有其他问题?
I will update a full tutorial later on how to implement a WebView
inside a ViewPager
, but I am getting a really weird issue that I don't understand how to fix.
Here are the implementations I'm running...
XML:
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/lastLoginText"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_below="@+id/PreferencesButton" >
</android.support.v4.view.ViewPager>
ViewPager Instantiate Object:
((ViewPager) collection).removeAllViews();
WebView a = webview[position];
((ViewPager) collection).addView(a);
Webviews are setup in a separate (InitWebViews)
webview[0] = new WebView(this.getApplicationContext());
webview[0].loadUrl("file:///android_asset/test.html");
webview[1] = new WebView(this.getApplicationContext());
webview[1].loadUrl("file:///android_asset/test.html");
webview[2] = new WebView(this.getApplicationContext());
webview[2].loadUrl("file:///android_asset/test.html");
Any ideas why it'd be like this, or how I can force the viewWidth
to be 1280? Or are there any other issues with the way I init the WebView
s?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论