第一次布局后无法获取viewWidth(ViewPager中的WebView)

发布于 2024-12-27 02:05:19 字数 1271 浏览 2 评论 0原文

稍后我将更新有关如何在 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 WebViews?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文