2017-01-25 3 views
0

webservice에서 가져온 이미지를 웹보기에 표시하고 싶습니다.안드로이드 - webview의 이미지가 화면에 맞지 않습니다.

동영상에 성공하여 화면에 맞을 수 있습니다.

이것은 css 코드입니다.

<style type="text/css"> 

    iframe { 
     display: block; 
     max-width:100%; 
     margin-top:10px; 
     margin-bottom:10px; 
    } 

    img { 
     display: block; 
     margin-top:10px; 
     margin-bottom:10px; 
     max-width:100%; 
     height:100%; 
     background-size: cover; 
     width: auto !important; 
     resize:both; 
     background:no-repeat fixed; 
    } 

</style> 

Google 검색을 기반으로하는 CSS 코드에서 많은 작업을 시도했지만 화면에 맞지 않았습니다.

다음이 CSS를 webview 콘텐츠에 추가합니다.

String str = "<style type=\"text/css\">\n" + 
      " iframe {\n" + 
      "  display: block;\n" + 
      "  max-width:100%;\n" + 
      "  margin-top:10px;\n" + 
      "  margin-bottom:10px;\n" + 
      " }\n" + 
      "\n" + 
      " img {\n" + 
      "   display: block;\n" + 
      "   margin-top:10px;\n" + 
      "   margin-bottom:10px;\n" + 
      "   max-width:100%;\n" + 
      "   height:100%;\n" + 
      "   background-size: cover;\n" + 
      "   width: auto !important;\n" + 
      "   resize:both;\n" + 
      "   background:no-repeat fixed;\n" + 
      "  }\n" + 
      "\n" + 
      "</style>"+currentNews.getContent(); 

그런 다음보기를로드합니다.

content.loadDataWithBaseURL("file:///android_asset/", str, "text/html", "utf-8", null); 

난 스케일링되지 않은 양식이나 자른 버전 만 받았습니다. 미리 감사드립니다.

this is non-scaled version

+0

아직 어떤 아이디어가 있습니까? – Hilal

답변

0

좋아 나는 문제가 무엇인지 발견했습니다. 외관상으로는 나의 html 자료는 서버 측에 또 다른 css 작풍을 얻고 있었다.

내 CSS 속성에 !important을 사용하여 내 스타일을 사용하도록 강제 할 수 있습니다. 그것은 완벽하게 작동하면 아주 좋은 느낌입니다.

<style type="text/css"> 
iframe { 
    display: block; 
    max-width:100%; 
    margin-top:10px; 
    margin-bottom:10px; 
} 

img { 
    height: auto !important; 
    max-width: 100% !important; 
    } 

</style> 

은 그 때 나는 str 내가 또한 str 문자열 변수에 다른 HTML 데이터를 추가 문자열 변수에 해당 스타일을 붙여 넣습니다. 그런 다음 아래 HTML을로드합니다.

content.loadDataWithBaseURL("file:///android_asset/", str, "text/html", "utf-8", null); 

그럼 트릭은 !important입니다.

관련 문제