[Android] Problème avec WebView

Problème avec WebView [Android] - Java - Programmation

Marsh Posté le 05-09-2011 à 17:11:07    

Bonjour,
 
J'ai un problème avec l'affichage de ma WebView : sa hauteur dépasse (parfois, souvent... à vrai dire aléatoirement!!) la hauteur de son contenu...
 
En fait ma WebView n'ai pas scrollable, car elle est contenu dans une ScrollView avec d'autres composants.
Pour être plus claire, dans mon Activity j'ai deux EditText, une ImageView, ma WebView, puis un troisième EditText (qui se retrouve donc aléatoirement distant de la WebView du dessus!)
 
Dans mon Layout:

Code :
  1. <ScrollView
  2. android:layout_width="fill_parent"
  3. android:layout_height="wrap_content" >
  4. <LinearLayout
  5. android:layout_width="fill_parent"
  6. android:layout_height="wrap_content" >
  7. <TextView
  8. android:id="@+id/txtArticleTitre"
  9. android:layout_width="fill_parent"
  10. android:layout_height="wrap_content" />
  11. <TextView
  12. android:id="@+id/txtArticleDate"
  13. android:layout_width="fill_parent"
  14. android:layout_height="wrap_content" />
  15. <LinearLayout
  16. android:layout_width="fill_parent"
  17. android:layout_height="wrap_content"
  18. android:gravity="center_horizontal" >
  19. <ImageView
  20.         android:id="@+id/imgArticle"
  21.         android:layout_width="320dip"
  22.         android:layout_height="220dip"
  23.         android:adjustViewBounds="true">
  24.         </ImageView>
  25. </LinearLayout>
  26. <WebView
  27. android:id="@+id/wvArticle"
  28. android:layout_width="wrap_content"
  29. android:layout_height="wrap_content" >
  30. </WebView>
  31. </LinearLayout>
  32. </ScrollView>


 
Dans mon Activity:

Code :
  1. WebView wv = (WebView)findViewById(R.id.wvArticle);
  2. wv.setScrollContainer(false);
  3. WebSettings webSettings = wv.getSettings();
  4. webSettings.setJavaScriptEnabled(true);
  5. webSettings.setPluginsEnabled(true);
  6. webSettings.setBuiltInZoomControls(false);
  7. webSettings.setSupportZoom(false);
  8. String pageHtml = "......"; // String contenant mon code HTML pour ma WebView
  9. wv.loadDataWithBaseURL(null, pageHTML, "text/html", "UTF-8", null);


 
J'attends un petit indice qui pourrait me donner une piste à explorer, car je désespère!! Ça fait plusieurs jours que je cherche en vain...
Merci d'avance :)

Reply

Marsh Posté le 05-09-2011 à 17:11:07   

Reply

Marsh Posté le 06-09-2011 à 12:12:00    

Personne n'a rencontré ce problème auparavant...???!!
 
Pour plus de précision, voici mon String pageHtml:

Code :
  1. String pageHTML = "<HTML> " +
  2.           "<HEAD>" +
  3.           "<link rel=\"stylesheet\" href=\"css/all.css\"> " +
  4.           "<link rel=\"stylesheet\" href=\"css/mdpi.css\" media=\"only screen and (-webkit-max-device-pixel-ratio:1.0) and (max-device-width:480px)\">" +
  5.           "<link rel=\"stylesheet\" href=\"css/hdpi.css\" media=\"only screen and (-webkit-min-device-pixel-ratio:1.5)\">" +
  6.           "<meta name=\"viewport\" content=\"user-scalable=no, width=device-width, target-densitydpi=device-dpi\">" +
  7.           "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" +
  8.           "<TITLE>Android| "+title+"</TITLE>" +
  9.           "<STYLE type=\"text/css\">" +
  10.           "P { text-align : justify; font-size:16px;  }" +
  11.           "BODY { height : 100%; width : auto;  }" +
  12.           ".conteneur_liste {" +
  13.           "max-width : "+mScreenWidth+"px;" +
  14.           "position: relative;" +
  15.           "float: left;" +
  16.           "height: auto;" +
  17.           "font-family:Arial, Helvetica, sans-serif;" +
  18.           "font-size: 16px;" +
  19.           "text-align: justify;" +
  20.           "bottommargin: 0; " +
  21.           "}" +
  22.           ".conteneur_liste img {" +
  23.           "width : "+(mScreenWidth-35)+"px;" +
  24.           "position:relative;" +
  25.           "float:left;" +
  26.           "height:auto;" +
  27.           "padding-left:5px;" +
  28.           "padding-bottom:10px;" +
  29.           "margin:0;" +
  30.           "}" +
  31.           ".auteur {" +
  32.           "height:auto;" +
  33.           "text-align:right;" +
  34.           "color:black;" +
  35.           "font-family:bold;" +
  36.           "padding-bottom:10px;" +
  37.           "}" +
  38.           "</STYLE>"  +
  39.           "<script type=\"text/javascript\">" +
  40.           "var currentSize = 16;" +
  41.           "var minSize = 12;" +
  42.           "var maxSize = 24;" +
  43.           "var h = 0;" +
  44.           "function AgrandirTaille() {" +
  45.           "currentSize += 2;" +
  46.           "currentSize = (currentSize<minSize) ? minSize : ((currentSize>maxSize) ? maxSize : currentSize);" +
  47.           "document.getElementById(\"content\" ).style.fontSize = currentSize+'px';" +
  48.           "}" +
  49.           "function ReduireTaille() {" +
  50.           "currentSize = currentSize-2;" +
  51.           "currentSize = (currentSize<minSize) ? minSize : ((currentSize>maxSize) ? maxSize : currentSize);" +
  52.           "document.getElementById(\"content\" ).style.fontSize = currentSize+'px';" +
  53.           "}" +
  54.           "</script>" +
  55.           "</HEAD>" +
  56.           "<BODY>" +
  57.           "<div class=\"conteneur_liste\">"+
  58.           "<p id=\"content\">"+description+"</p>"+
  59.           "<p class=\"auteur\">"+auteur+"</p>"+
  60.           "</div>"+
  61.           "</BODY>" +
  62.           "</HTML>";


Message édité par sssbenj le 06-09-2011 à 17:39:39
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed