dialog内部webview显示网页生成的二维码(网页非图)宽度问题
来源:互联网 发布:51单片机flash多大 编辑:程序博客网 时间:2024/06/09 14:42
使用webview外部布局必须填满或设置高度,所以布局如下[二维码原背景为无,chrome显示为黑色,坑。。。]:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="horizontal"> <WebView android:id="@+id/web" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scrollbars="none" android:layout_gravity="center_horizontal"/></LinearLayout>
final View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.qrcode,null);final android.webkit.WebView web = (android.webkit.WebView) view.findViewById(R.id.web);web.getSettings().setUseWideViewPort(true);web.getSettings().setLoadWithOverviewMode(true);if(qrDialog == null){ qrDialog = new AlertDialog.Builder(MainActivity.this) .setView(view).create();}getProgressDialog().show();final android.view.WindowManager.LayoutParams p = qrDialog.getWindow().getAttributes();final ViewGroup.LayoutParams params = web.getLayoutParams();vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { view.getViewTreeObserver().removeOnGlobalLayoutListener(this); }else view.getViewTreeObserver().removeGlobalOnLayoutListener(this); int height = view.getHeight(); params.width = PictureUtil.dip2px(MainActivity.this,height); params.height = PictureUtil.dip2px(MainActivity.this,height); p.width = PictureUtil.dip2px(MainActivity.this,height)+70; qrDialog.getWindow().setAttributes(p); web.setLayoutParams(params); } });web.setWebViewClient(new WebViewClient(){ @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); getProgressDialog().dismiss(); qrDialog.show(); }}); web.loadUrl("二维码网址。。。");
比较坑的是,还是做不到长宽一致只能保证二维码显示是完整的,所以这里加了一个数字,看起来稍微自然。
p.width = PictureUtil.dip2px(MainActivity.this,height)+70;
阅读全文
0 0
- dialog内部webview显示网页生成的二维码(网页非图)宽度问题
- webview 的网页显示
- webview显示html网页文件的问题
- 网页生成二维码的例子
- 网页自动生成二维码
- 网页自动生成二维码
- servlet网页生成二维码
- qt5.5 webview无法显示网页问题
- android webview显示网页空白问题
- 网页端生成二维码的实现方式
- WebView显示网页
- 使用webView显示网页
- WebView显示网页
- 使用WebView显示网页
- WebView显示完整网页
- 使用WebView显示网页
- 控件WebView显示网页
- WebView显示网页
- Java设计模式-设计模式的六种原则总结
- iOS OS X 和 iOS 中的多线程技术-4.1 (GCD)
- 【Scikit-Learn 中文文档】二十六:密度估计
- 每日练习
- struct字节对齐问题
- dialog内部webview显示网页生成的二维码(网页非图)宽度问题
- Python基础篇之tuple一.(创建tuple)
- 深度学习中向量化与非向量化计算的差别
- BZOJ 4552: [Tjoi2016&Heoi2016]排序 二分 线段树
- PointNet++阅读笔记
- 每日练习
- centos7下用内核源码单独编译安装KVM模块
- 滚蛋吧,python2君!
- GridView行编辑、更新、取消、删除事件用法