2011-10-10 3 views
1

Si ma WebView est si grande, je n'ai aucun problème et la hauteur de WebView correspond à la hauteur de l'écran, même lorsque le contenu est si grand que je peux faire défiler le contenu de WebView. Toutefois, si le contenu de WebView est faible, la hauteur de WebView ne correspond pas à l'écran.Comment adapter la taille de la hauteur WebView à la hauteur de l'écran?

C'est ma mise en page:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" > 

<ScrollView android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
     android:fitsSystemWindows="true"> 

    <WebView android:id="@+id/webview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fitsSystemWindows="true" /> 

</ScrollView> 

<LinearLayout android:id="@+id/media_player" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:visibility="visible"> 

    <Button android:textStyle="bold" 
     android:id="@+id/ButtonPlayStop" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@android:drawable/ic_media_play" /> 

    <SeekBar android:id="@+id/SeekBar" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_below="@id/ButtonPlayStop" /> 

</LinearLayout> 

Voici la capture d'écran:

enter image description here

Toute personne peut me aider à résoudre ce problème?

Répondre

8

Vous n'avez pas besoin de placer un WebView à l'intérieur d'un ScrollView car il sait déjà comment faire défiler lorsque son contenu est plus grand que ses limites de vue. Placer des vues défilantes à l'intérieur d'autres vues défilantes a tendance à entraîner un comportement indésirable. Si l'on ne tient pas compte de cela pendant une seconde, un ScrollView ne s'étire pas pour occuper un espace vide supplémentaire si son contenu est trop petit. C'est-à-dire, à moins que le drapeau spécial (android:fillViewport) soit utilisé.

En tant que solution, je voudrais supprimer le ScrollView extérieur et essayer de faire le WebView prendre l'espace par son propre droit. Si vous utilisez un RelativeLayout comme conteneur, vous pouvez obtenir cette mise en page avec un seul niveau de profondeur:

  • bouton de lecture passe en bas à gauche du parent
  • barre de recherche va au fond et à droite de la pièce bouton
  • WebView est au-dessus avec fill_parent en largeur et hauteur

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    
    <Button android:textStyle="bold" 
    android:id="@+id/ButtonPlayStop" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:background="@android:drawable/ic_media_play" /> 
    
    <SeekBar android:id="@+id/SeekBar" 
    android:layout_toRightOf="@+id/ButtonPlayStop" 
    android:layout_alignParentBottom="true" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_below="@id/ButtonPlayStop" /> 
    
    <WebView android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_above="@id/ButtonPlayStop" /> 
    
    </RelativeLayout> 
    
+0

Votre réponse était très grande. Merci de votre aide. J'ai appris que je devais travailler plus avec RealtiveLayout http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html –

Questions connexes