的Andr​​oid的WebView文本变焦不同屏幕和操作系统版本 [英] Android WebView text zoom for different screens and os version

查看:171
本文介绍了的Andr​​oid的WebView文本变焦不同屏幕和操作系统版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,大家好,我已经被设计为在智能手机和平板电脑都运行一个应用程序。
当它运行在平板电脑我想我变焦的WebView的文本,让用户阅读更好的文本,以填补所有空白区域,如果有可能。

Good morning guys, I've an app that is designed to work both on smartphone and tablet. When it runs on tablet I want to zoom the text of my webview to allow users to read better the text and to fill all the empty space if it's possible.

这在code,我使用做的伎俩:

This the code that I'm using to do that trick:

//Webview Zoom
            if( UIUtils.isTablet(getActivity())) {
                if(UIUtils.isICS()) {
                    webView.getSettings().setTextZoom(130);
                } else {
                    int currentTextSizeIndex = lyricsView.getSettings().getTextSize().ordinal();
                    if ( currentTextSizeIndex+1 < lyricsView.getSettings().getTextSize().values().length )
                        webView.getSettings().setTextSize( lyricsView.getSettings().getTextSize().values()[currentTextSizeIndex+1] );
                }
            }

所以我检查,如果我是在平板电脑上,我检查哪个操作系统版本用户使用。
从API等级14逸岸,我可以使用 setTextZoom 这让我设置页面中的百分比文字缩放(默认为100)。该溶液becaue得多更可扩展的I例如可以给用户增加或他们想与步骤+10或-10%的减小文本的能力。

So I check if I'm on a tablet and I check which OS version user is using. Infact from API Level 14 I can use setTextZoom that allow me to set the text zoom of the page in percent (default 100). This solution is much much more scalable becaue I can for example give to the user the ability to increase or decrease the text as they want with +10 or -10 percent of step.

API等级14之前,我必须使用<一个href=\"http://developer.android.com/reference/android/webkit/WebSettings.html#setTextSize%28android.webkit.WebSettings.TextSize%29\"相对=nofollow>使用一个枚举作为参数setTextSize (默认正常)。
TEXTSIZE是枚举指定文本大小。最小的是小50%,75%师范大学较大100%,150%,最大的是200%

Before API Level 14 I have to use setTextSize that use an enum as parameter (default NORMAL). TextSize is Enum for specifying the text size. SMALLEST is 50% SMALLER is 75% NORMAL is 100% LARGER is 150% LARGEST is 200%

所以,我只能使用这5个costants,它是不那么可扩展性(但它给这个功能将90%的手机没有ICS的唯一途径:D)。

So I can use only these 5 costants and it's not so scalable (but it's the only way to give this feature to the 90% of the phones that don't have ICS :D).

问题是, webView.getSettings()setTextSize(TextSize.LARGER); 以不同的方式行事时,我说明了在不同粒文本视图,它真的没有ok了。

The problem is that webView.getSettings().setTextSize(TextSize.LARGER); acts in different ways when I show the text view in different tablets and it's really not ok.

目前,我在三星Galaxy Tab和Kindle Fire的测试时刻。
这些都是高技术规格从GSMArena:

At the moment I'm testing on a Samsung Galaxy Tab and a Kindle Fire. These are the tech specifications from GSMArena:

三星P1000 Galaxy Tab的

显示结果
类型TFT电容式触摸屏,1600万色

Display
Type TFT capacitive touchscreen, 16M colors

大小 600 x 1024像素,7.0英寸(170〜PPI像素密度)

亚马逊Kindle Fire

显示结果
键入IPS TFT电容式触摸屏,1600万色

Display
Type IPS TFT capacitive touchscreen, 16M colors

大小 1024×600像素,7.0英寸(170〜PPI像素密度)

正如你可以看到它们具有相同的分辨率,英寸和PPI!
现在,我会告诉你2截图(相同的WebView内容)形成这些设备,所以你undersand我在说什么。

As you can see they have the same resolutions, inches and ppi! Now I'll show you 2 screenshots (of the same webview content) form those devices so you undersand what I'm talking about.

KindleFire:

KindleFire:

Galaxy Tab的:

Galaxy Tab:

在与TEXTSIZE大文本Galaxy Tab的是太多的大,这是ulgy看到的。因此,对于那种设备是更好地展示默认为普通文本(并让用户最佳的选择,如果把它放在更大)。但我怎么能知道哪个是最好看的默认TEXTSIZE显示?由于师范大学是确定的Galaxy Tab和太小的Kindle Fire和大过大的Galaxy Tab,但完美的Kindle。我做的只是在这两个设备的测试,但我已经支持的设备我已经找到某种参数的所有平板电脑,differencs为了说:这个设备就ok了,因为分辨率是小我会把更大/正常的,而不是在这一个,因为它是大resulution我可以把它做大(种)。

On the Galaxy Tab with the textSize LARGE the text is too much big and it's ulgy to see. So for that kind of the device is better to show a NORMAL text by default (and let the user choise if put it bigger). But how can I know which is the best looking default textSize to show? Because NORMAL is ok for Galaxy Tab and too small for Kindle Fire and LARGE is too big for galaxy tab but perfect for Kindle. I'm doing a test only on these 2 devices but I've to support all tablets I've to find some kind of parameters, differencs in devices in order to say: ok on this device because resolutions is small I'll put bigger/normal, instead on this one because it's bigger resulution I can put it bigger (kind of).

你有没有遇到这个问题?我该如何解决呢?

Have you ever faced this problem? How can I solve it?

推荐答案

我们已经看到了我们的应用程序,以这种类似的问题(一般,不只是在网页视图)。

We've seen similar issues to this in our app (in general, not just in WebViews).

原三星Galaxy Tab错误地报告本身一样大,华电国际。用相同的屏幕尺寸(7英寸),分辨率(1024×600),其他平板电脑正确地报告自己的大MDPI。这些正确的平板电脑包括的Kindle Fire,Nook的平板电脑,甚至是三星Galaxy Tab 2!我期望HTC Flyer的做同样的,但还没有尝试过。

The original Samsung Galaxy Tab incorrectly reports itself as large-hdpi. Other tablets with the same screen size (7 inches) and resolution (1024x600) correctly report themselves as large-mdpi. These "correct" tablets include the Kindle Fire, Nook Tablet, and even the Samsung Galaxy Tab 2! I would expect the HTC Flyer to do the same but haven't tried it.

在一个博客帖子谷歌宣称,这是由三星提出了设计决策:

In one blog post Google claimed this was a design decision made by Samsung:

<一个href=\"http://android-developers.blogspot.co.uk/2010/09/screen-geometry-fun.html\">http://android-developers.blogspot.co.uk/2010/09/screen-geometry-fun.html (搜索惊喜)

在另一个,他们声称这是一个错误:

In another, they claimed it was a mistake:

<一个href=\"http://android-developers.blogspot.co.uk/2011/07/new-tools-for-managing-screen-sizes.html\">http://android-developers.blogspot.co.uk/2011/07/new-tools-for-managing-screen-sizes.html (搜索有趣)。

无论哪种方式,原来的Galaxy Tab是一个例外,这不应该被允许再次发生。

Either way, the original Galaxy Tab is an exception, and this shouldn't be allowed to happen again.

我建议与任何会最好看的火象应为除原有的Galaxy Tab 7的所有英寸平板电脑工作。如果你可以使它看起来可以接受的有太多,那么它是一个不错的奖金。

I recommend going with whatever looks best on the Fire as that should work well for all 7 inch tablets except the original Galaxy Tab. If you can make it look acceptable on there too, then it's a nice bonus.

希望帮助!

这篇关于的Andr​​oid的WebView文本变焦不同屏幕和操作系统版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆