gpt4 book ai didi

android - Webview 不能在对话框中水平滚动

转载 作者:行者123 更新时间:2023-11-29 18:02:29 25 4
gpt4 key购买 nike

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

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

Output

最佳答案

从代码中删除尺寸参数,并将其设置为 fill_parent,这样它也将水平滚动

关于android - Webview 不能在对话框中水平滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15170893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com