3

独自のアプリを作成するためのこれまでになく厳しい努力の中で、私はさらに別のレンガの壁にぶつかりました。

詳細

私は今日、WebViewズームコントロールが組み込まれているので、そこから移行することにしましたImageView...私の問題は、API 3を実行しているアクティブなユーザーがまだいるということです...更新を書くときは、そのことを覚えておく必要がありますこのアプリ

私は何をしようとしていますか?

サーバーから画像をロードWebViewし、画面によってサイズが異なるウィンドウに合わせて表示するだけです。

何を試しましたか

#1を試してください(私の個人的な試み)

//iW & iH are the height and width of the image passed from the server
//Calc the scale needed to fit width
int scW = (int) ((iW / (float)wView.getMeasuredHeight()) * 100);
//Calc the scale needed to fit height
int scH = (int) ((iH / (float)wView.getMeasuredHeight()) * 100);
//fit the bigger of the 2
if (scW < scH)
{
    wView.setInitialScale(scW);
}
else
{
    wView.setInitialScale(scH);
}
String pUrl = "http://app.guycothal.com/Funnys/2012724133312929.png";
wView.loadUrl(pUrl);

これにより、すべての写真に多くの空きスペースがある写真が残ります

#2を試してください(StackOverFlowで見つかりました)

String pUrl = "http://app.guycothal.com/Funnys/2012724133312929.png";
String html="<html><body><img src=\"" + pUrl + 
    "\" width=\"10%37\" height=\"10%37\"/></body></html>";
wView.loadData(html, "text/html", "utf-8");

これにより、画像が巨大になります...つまり、巨大です

#3を試してください(StackOverFlowで見つかりました)

wView.setWebViewClient(null);
wView.getSettings().setJavaScriptEnabled(true);
wView.getSettings().setLoadWithOverviewMode(true);//NEeds api 7
wView.getSettings().setUseWideViewPort(true);
wView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
wView.getSettings().setBuiltInZoomControls(true);
wView.getSettings().setSupportZoom(true); 
wView.getSettings().setUseWideViewPort(true);
wView.setScrollbarFadingEnabled(false);//Needs api 5
String pUrl = "http://app.guycothal.com/Funnys/2012724133312929.png";
wView.loadUrl(pUrl);

必要なAPIと3つ以上のAPI以外...それらの行がなくても、画像が再び巨大になります

#4を試してください(ここでも見つかりました!!! <---少なくとも最初に検索します)

wView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
String pUrl = "http://app.guycothal.com/Funnys/2012724133312929.png";
wView.loadUrl(pUrl);

Froyo (API 7) 以降が必要

_ #5 を試す (考えすぎてこの質問を書きながら試しました)

//iW & iH are the height and width of the image passed from the server
int iMW = imgView.getMeasuredWidth();
int iMH = imgView.getMeasuredHeight();
int scW = (int) ((iW / (float)iMW) * 100);
int scH = (int) ((iH / (float)iMH) * 100);
if (iMW < iW && iMH < iH)
{
    if (scW < scH)
    {
        wView.setInitialScale(scW);
    }
    else
    {
        wView.setInitialScale(scH);
    }
}
if (iMW < iW && iMH > iH)
{
    wView.setInitialScale(scH);
}
if (iMW > iW && iMH < iH)
{
    wView.setInitialScale(scW);
}
if (iMW < iW && iMH < iH)
{
    if (scW > scH)
    {
        wView.setInitialScale(scW);
    }
    else
    {
        wView.setInitialScale(scH);
    }
}
wView.loadUrl(pUrl);

次は何ですか?

ここからどこへ行けばいいのかわからない...この1つの簡単なことで一日中自殺してきた...髪を抜く前に助けてください

ps私はハゲです...だから、これは冗談です

4

1 に答える 1

3

#5作業してみてください!!!

        int iMW = imgView.getMeasuredWidth();
        int iMH = imgView.getMeasuredHeight();
        //Had the imw and iw backward...same for height
        int scW = (int) ((iMW / (float)iW) * 100); 
        int scH = (int) ((iMH / (float)iH) * 100);
        int fScale = 0;
        if (iMW < iW && iMH < iH)
        {
            if (scW < scH)
            {
                fScale = scW;
            }
            else
            {
                fScale = scH;
            }
        }
        if (iMW < iW && iMH > iH)
        {
            fScale = scW;
        }
        if (iMW > iW && iMH < iH)
        {
            fScale = scH;
        }
        //had signs backwards...DUH
        if (iMW > iW && iMH > iH)
        {
            if (scW < scH)
            {
                fScale = scW;
            }
            else
            {
                fScale = scH;
            }
        }
        wView.setInitialScale(fScale);
        wView.loadUrl(pUrl);
于 2012-07-25T02:12:27.107 に答える