3

I am using WebView to show parsed XML and HTML content. I have set the layout_height of webview to wrap_content. It works fine when the matter is large in size but when the matter is small it do not wrap to it the below space remains white. pls tell me how to wrap it each time when I change content in webView.

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

<LinearLayout  android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background = "#ffffff" >

 <WebView android:layout_height = "wrap_content"
  android:layout_width = "wrap_content" 
  android:id = "@+id/webcontent"    
   />  

<LinearLayout android:layout_width = "fill_parent"
 android:layout_height = "wrap_content"
 android:orientation = "horizontal"
 android:id = "@+id/buttons"
 android:background="#ffffff">
 <Button android:layout_height = "wrap_content"
     android:layout_width = "0dp" 
     android:id = "@+id/previousdata"         
     android:text = "Back"
     android:layout_weight = "1"
      android:layout_gravity="center_vertical"/>
   <Button android:layout_height = "wrap_content"
     android:layout_width = "0dp" 
     android:id = "@+id/nextdata"
     android:layout_weight = "1"
     android:text = "Next"
     android:layout_gravity="center_vertical"/>
  </LinearLayout>
</LinearLayout> 
 </ScrollView>

Now I am getting the problem that if I am running my app in portrait mode the webView is giving extra white space and not contracting according to the data, but if I change the orientation to landscape the white space diminished... Plz explain what's happening to my view and how can I diminish the extra white space... thanx in advance...

Aashutosh Sharma
  • 1,483
  • 2
  • 17
  • 29

1 Answers1

3

Android property: android:layout_weight = "1 in the layout should work...

Bhavin Nattar
  • 3,189
  • 2
  • 22
  • 30
letroll
  • 1,059
  • 1
  • 14
  • 36
  • 1
    No sir... I have tried it again when you mention here but it doesn't.. please provide some solution... thanx in advance.. – Aashutosh Sharma Jun 09 '12 at 07:32
  • it works but only if we have a linear layout as a parent, if we make that linear layout as a child of scroll view it doesn't work then.. – Aashutosh Sharma Jul 02 '12 at 07:22
  • did you use android:layout_height="0dp" ? – letroll Jul 02 '12 at 08:19
  • no it has matter, when i use such approach the view totally disappear, but now I have used webview all alone in linearlayout and have eliminated the scrollview parent and its working fine to me. But if you can check it out that why its not working in a scroll view then pls do tell.. – Aashutosh Sharma Jul 02 '12 at 10:51
  • hi, add you webview in linearlayout and then try with android:layout_weight = "1" – Android Mar 20 '13 at 09:09
  • What height do you use for LinearLayout? wrap_content? With wrap_content and 0dp on WebView it's height 0. What am I doing wrong? Sorry for necroposting. – vyndor Mar 28 '16 at 14:51