我正在对话框中加载 webview,但它不是水平滚动。以下是我的代码。
@Override
protected void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0);
TwitterDialog fb = new TwitterDialog(this);
fb.abc();
}
class TwitterDialog extends Dialog {
Context context;
String url = "https://www.facebook.com";
public TwitterDialog(Context context) {
super(context);
this.context = context;
}
void abc() {
LinearLayout mContent = new LinearLayout(context);
mContent.setOrientation(LinearLayout.VERTICAL);
final float scale = context.getResources().getDisplayMetrics().density;
float[] dimensions = new float[] { 400.0f, 500.0f };
addContentView(mContent, new FrameLayout.LayoutParams(
(int) (dimensions[0] * scale + 0.5f), (int) (dimensions[1]
* scale + 0.5f)));
FrameLayout.LayoutParams FILL = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
ScrollView _scroll = new ScrollView(MyMainActivity.this);
_scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
WebView mWebView = new WebView(context);
mWebView.setWebViewClient(new WebClicent());
mWebView.setScrollbarFadingEnabled(false);
mWebView.setHorizontalScrollBarEnabled(true);
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.getSettings().setUseWideViewPort(true);
mWebView.loadUrl(url);
mWebView.setLayoutParams(FILL);
// _scroll.addView(mWebView);
mContent.addView(mWebView);
TwitterDialog.this.show();
}
}
private class MyWebViewClient extends WebViewClient {
@Override
// show the web page in webview but not in web browser
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
我得到以下输出。但它不是水平滚动。