1

我正在对话框中加载 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;
        }
}

我得到以下输出。但它不是水平滚动。

输出

4

2 回答 2

3

从代码中删除尺寸参数,并让它成为 fill_parent ,这样它也会水平滚动

于 2013-03-02T04:58:46.220 回答
0

嘿将此代码添加到您的网络视图

       WebView mWebView = new WebView(context);

       mWebView.setWebViewClient(new WebClicent());
       mWebView.setScrollbarFadingEnabled(false);
       mWebView.setHorizontalScrollBarEnabled(true);
       mWebView.setWebViewClient(new MyWebViewClient());
       mWebView.getSettings().setUseWideViewPort(true);

这是额外的代码,请将其添加到上面的代码中并检查一次

    mWebView.getSettings().setBuiltInZoomControls(false);
    mWebView.getSettings().setLoadWithOverviewMode(false);
    mWebView.getSettings().setUseWideViewPort(false);
    mWebView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
于 2013-03-02T05:02:38.957 回答