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>
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.
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.
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 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.
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
I faced the same issue and solved it by adding :android:layout_gravity="top"
to the LinearLayout
inside the ScrollView
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With