Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrollview leaves extra space at bottom of layout activity

My Scrollview leaves space under some layouts I'm new to android please, help here is my code:

 <ScrollView     
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollviewdb"     
    android:layout_width="match_parent"    
    android:layout_height="wrap_content" >  
    <LinearLayout    
      xmlns:android="http://schemas.android.com/apk/res/android" 
              android:orientation="vertical"    
              android:layout_width="match_parent"    
              android:layout_height="wrap_content">    
         <TextView        
            android:layout_width="match_parent"   
            android:layout_height="wrap_content"         
            android:textSize="15sp"  
            android:padding="5dp"     
            android:id="@+id/ghavaed_text"/> 
      </LinearLayout>
  </ScrollView>
like image 366
Erik_DA Avatar asked Aug 31 '16 08:08

Erik_DA


People also ask

How does a ScrollView scroll its child content?

A ScrollView can only have a single child, which can be other layouts. It's therefore common for a ScrollView to be the root layout on a page. To scroll its child content, ScrollView computes the difference between the height of its content and its own height. That difference is the amount that the ScrollView can scroll its content.

Why is ScrollView the root layout on a page?

It's therefore common for a ScrollView to be the root layout on a page. To scroll its child content, ScrollView computes the difference between the height of its content and its own height. That difference is the amount that the ScrollView can scroll its content.

What is a ScrollView in Xamarin?

By default, a ScrollView scrolls vertically, which reveals more content: The equivalent C# code is: For more information about bindable layouts, see Bindable Layouts in Xamarin.Forms. A ScrollView can be a child layout to a different parent layout. A ScrollView will often be the child of a StackLayout.

When does the Scroll View stop on the next index?

When true, the scroll view stops on the next index (in relation to scroll position at release) regardless of how fast the gesture is. This can be used for pagination when the page is less than the width of the horizontal ScrollView or the height of the vertical ScrollView.


3 Answers

Add android:fillViewport in your ScrollView.

<ScrollView     
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollviewdb"     
    android:fillViewport="true"
    android:layout_width="match_parent"    
    android:layout_height="wrap_content" >  
    <LinearLayout    
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical"    
      android:layout_width="match_parent"    
      android:layout_height="wrap_content">    
         <TextView        
            android:layout_width="match_parent"   
            android:layout_height="wrap_content"         
            android:textSize="15sp"  
            android:padding="5dp"     
            android:id="@+id/ghavaed_text"/> 
    </LinearLayout>
</ScrollView>

As @Ironman explained, The reason behind this is ScrollView would become useless if its content was always as tall as itself. To work around this, you need to use the ScrollView attribute called android:fillViewport. When set to true, this attribute causes the scroll view’s child to expand to the height of the ScrollView if needed. When the child is taller than the ScrollView, the attribute has no effect

like image 158
fluffyBatman Avatar answered Nov 15 '22 09:11

fluffyBatman


I faced the same issue and solved it by adding :android:layout_gravity="top" to the LinearLayout inside the ScrollView.

like image 20
Asaye Avatar answered Nov 15 '22 09:11

Asaye


You can add marginBottoom with minus value on scrollview.

Also in my case, I found that the background height takes more space on the bottom. solution: I have moved the background from the relative layout to the scroll view and it has been solved this problem.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:fillViewport="true"
android:background="@drawable/bg" //i move this background here from realative 
    layout
android:overScrollMode="never"
>
 <RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
  </RelativeLayout>
  </ScrollView>

hope this solves your problem

like image 26
Khalil Abubaker Avatar answered Nov 15 '22 08:11

Khalil Abubaker