在第一个布局之后无法获得viewWidth(ViewPager中的WebView)

时间:2012-01-12 16:49:39

标签: android android-layout view android-webview android-viewpager

稍后我将更新一个完整的教程,了解如何在WebView内部实现ViewPager,但我得到一个非常奇怪的问题,我不明白如何修复。

以下是我正在运行的实现......

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);

Webview是在单独的(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的方式还有其他问题吗?

0 个答案:

没有答案