我正在製作一個應用程序,該應用程序具有與其他元素嵌套在一起的Webview內嵌在ScrollView中的應用程序。我注意到,在ICS中,在Galaxy Nexus設備上進行測試時,當頁面被瀏覽時,WebView似乎與其餘顯示的元素不相關,導致WebView顯示爲浮動,因爲其值爲幾ms滯後於繪圖。在2.x版本的Android中不會發生這種情況(未在3.x上測試)。這裏有一個浮動效果的視頻http://www.youtube.com/watch?v=avfBoWmooM4(你可以清楚地看到,如果你設置爲全屏1080p)在ICS中脫節的WebView繪圖
任何人都可以提出爲什麼會發生這種情況,或修復?
我設置一個測試項目,下面,向人們展示:
package com.martynhaigh.floating_web_view;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
public class FloatingWebViewTestActivity extends FragmentActivity {
public final int viewId = 0x12345678;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
FrameLayout frame = new FrameLayout(this);
frame.setId(viewId);
setContentView(frame, lp);
FloatingWebViewICSFragment fragment = new FloatingWebViewICSFragment();
getSupportFragmentManager().beginTransaction().add(viewId, fragment).commit();
}
public static class FloatingWebViewICSFragment extends Fragment {
private final String htmlBody = "<html><body><p style=\"font-size:1.5em\">This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. This is a test document. </body></html>";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
TextView textView = new TextView(getActivity().getApplicationContext());
textView.setText("Test Activity");
WebView webView = new WebView(getActivity().getApplicationContext());
webView.loadDataWithBaseURL("file:///android_asset/", htmlBody, "text/html", "UTF-8", "about:blank");
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.setScrollContainer(false);
TextView textView2 = new TextView(getActivity().getApplicationContext());
textView2.setText("Test Activity");
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
LinearLayout layout = new LinearLayout(getActivity().getApplicationContext());
layout.setLayoutParams(lp);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(textView);
layout.addView(webView);
layout.addView(textView2);
ScrollView scrollView = new ScrollView(getActivity().getApplicationContext());
scrollView.setLayoutParams(lp);
scrollView.addView(layout);
return scrollView;
}
}
}