首页 \ 问答 \ WebView无法正确缩放?(WebView not scaling correctly?)

WebView无法正确缩放?(WebView not scaling correctly?)

我正在使用WebView将HTML转换为图像。 HTML具有600px的固定(使用CSS定义)。

WebView布局是:

<WebView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none"/>

在加载html文档时,我通过执行以下操作来获取webview大小:

int width = webView.getMeasuredWidth();
int height = webView.getMeasuredHeight();

我注意到的第一个奇怪的事情是宽度是650.文档显示,我需要水平滚动才能查看它(lo-res设备)。

下一步是将webview转换为图像:

bitmap = Bitmap.createBitmap(600, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
webView.draw(c);

但是,将webview转换为位图会从右侧部分(webview中不可见的区域)中移除。

当我在HTML文档中定义600时,为什么webview宽度为650? 为什么成像裁剪?


I'm using a WebView to convert an HTML to an image. The HTML has a fixed with of 600px (defined using CSS).

The WebView layout is:

<WebView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none"/>

On loading the html document, I get the webview size by doing:

int width = webView.getMeasuredWidth();
int height = webView.getMeasuredHeight();

The first weird thing that I notice is that the width is 650. The document is displayed and I need to scroll horizontally to view it all (lo-res device).

The next step is to convert the webview into an image:

bitmap = Bitmap.createBitmap(600, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
webView.draw(c);

However, converting the webview into the bitmap crops off the right part (the area where is not visible in the webview).

Why is the webview width 650 when I defined 600 in my HTML document? And why is imaged cropped?


原文:https://stackoverflow.com/questions/31378150
更新时间:2022-11-23 18:11

最满意答案

MDN上的箭头功能文章:

(param1, param2, …, paramN) => { statements }
(param1, param2, …, paramN) => expression

您可以看到,无支撑语法要求箭头右侧的代码是一个表达式 ,这是语言本身所做的(不幸的) 区分

由于debugger是一种语句,因此在任何需要使用表达式的地方使用它都是语法错误。 有一件事你可以去解决这个问题,就是把你的调试器语句转换成一个表达式,然后你就可以把JavaScript当作评估对象而不是返回,例如:

function debug(args) {
     debugger;
     return true;
}

params => debug() && params + 1

// or

params => console.log(params) || params + 1

这样做的方式是因为逻辑运算符在JavaScript中的作用方式,这是真的:

truthyA && B  === B

falsyA || B === B

链接逻辑运算符时,JavaScript会从左到右评估子表达式,然后根据其布尔等效值进行操作。 这就是为什么你有时会看到&&用来代替if语句:

 if (smth) doStuff();
 // is equivalent to:
 smth && doStuff();

From the MDN article on arrow functions:

(param1, param2, …, paramN) => { statements }
(param1, param2, …, paramN) => expression

You can see that the brace-less syntax requires the code on the right of the arrow to be an expression, which is an (unfortunate) distinction made by the language itself.

Since debugger is a statement, using it anywhere an expression is expected is a syntax error. One thing you could to to work around this is to transform your debugger statement in an expression which you trick JavaScript into evaluating but not returning, e.g.:

function debug(args) {
     debugger;
     return true;
}

params => debug() && params + 1

// or

params => console.log(params) || params + 1

The way this works is that because of the way logical operators function in JavaScript, this is true:

truthyA && B  === B

falsyA || B === B

When chaining logical operators, JavaScript evaluates sub-expressions left to right and then act depending on their boolean equivalent. That's why you'll sometimes see && used in place of if statements:

 if (smth) doStuff();
 // is equivalent to:
 smth && doStuff();

相关问答

更多
  • this在handleAuthResult是undefined ,因为handleAuthResult不是箭头函数,因此没有词法。 这是一个普通的原型函数(松散地,“方法”),这意味着它是由它的调用方式定义的。 你打电话的方式: authenticate(callback) { callback({ value: true }); } 不会this设置为任何特定的,因此this是undefined (因为您处于严格模式)。 要解决this问题,请将其传递给authentic ...
  • 箭头功能提供了一个词汇。 它使用在评估函数时可用的this一点。 它在逻辑上相当于(以下不是有效的代码,因为你不能有一个名为this的变量): (function(this){ // code that uses "this" })(this) 在你的第一个例子中,箭头函数在构造函数中,并且指向新生成的实例。 在你的第三个例子中,没有使用箭头函数,标准的this行为一如既往(这在函数范围中)。 在你的第二个例子中,你使用了一个箭头函数,但是在它被评估的范围内, this是全局/未定义的。 Arro ...
  • 箭头函数定义如下: ArrowFunction[In, Yield] : ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In] ConciseBody[In] : [lookahead ≠ { ] AssignmentExpression[?In] { FunctionBody } 而throw是一个声明: ThrowStatement[Yield] : throw [no LineTer ...
  • 从MDN上的箭头功能文章: (param1, param2, …, paramN) => { statements } (param1, param2, …, paramN) => expression 您可以看到,无支撑语法要求箭头右侧的代码是一个表达式 ,这是语言本身所做的(不幸的) 区分 。 由于debugger是一种语句,因此在任何需要使用表达式的地方使用它都是语法错误。 有一件事你可以去解决这个问题,就是把你的调试器语句转换成一个表达式,然后你就可以把JavaScript当作评估对象而不是返回, ...
  • 在这个特殊情况下,库正在改变this在decorate回调中引用的内容。 使用箭头函数( => )时, this与外部作用域的作用相同。 这意味着你基本上坚持使用这个function 。 In this particular case, the library is changing what this refers to inside the callback for decorate. When using arrow functions (=>), this is equivalent to the ...
  • 您可以使用event.currentTarget来引用处理程序的目标元素 $(document).on('click', '.inserted-el', function(event) { snippet.log('old -> ' + this.innerHTML + ':' + event.currentTarget.innerHTML); }); $(document).on('click', '.inserted-el', (event) => { snippet.log('new ...
  • 如果你不想要词汇限制,那么就不需要使用箭头功能了。 如果你想动态绑定this ,只是不要使用箭头功能。 当然,您可以废弃.bind({})作为一个整体,并使用通过将所有内容放入对象方法(或示例中的IIFE)中绑定到对象的箭头函数: (function() { this; // the value that everything is bound to double(2).then(result => { this.double = result; // store result here ...
  • 在所有使用的浏览器都支持使用ES6语法之前,它是否聪明? 不是真的。 你可以将它转换为例如babel (这就是你举起的Bootstrap v4, 也是如此 )。 实际上,即使您确保使用现代JS运行时,也可以使用babel进行转换,以使用尚未完全标准化的语言功能 。 重点不是新的用户可见功能,而是程序员的工作效率,您可以通过ES6以多种方式提升。 您将在此博客文章中找到有关如何使用babel转换浏览器预期代码的明确说明。 因为在没有ES6的情况下,ES6可能实现的所有功能都是可能的,所以我看不出如何使用新语法 ...
  • 示例一和示例二之间的主要区别在于示例一使用调用范围,而示例二使用Meteors范围。 如果我不得不猜测它会不起作用,因为你正在使用this并期望一个不同的范围。 这是一个演示此功能的快速示例... (function () { var Example = (function () { function Example() { setTimeout(function() { console.log(this); //this == ...
  • 我想你想要的 var F = s => /[^aeiou]{3}|[jqxz]/.test(s); 这会创建一个箭头函数 ,它接收一个参数s并返回/[ /[^aeiou]{3}|[jqxz]/.test(s) 。 并且该函数被赋值给变量F 请注意,您还可以使用在ES5中工作的不太长的替代方案,并且应该执行得更好,因为它不会在每次调用时重新创建正则表达式对象。 var F = /(?:)/.test.bind(/[^aeiou]{3}|[jqxz]/); I think you want var F = ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。