Linearlayout Not Expanding Inside a Scrollview

LinearLayout not expanding inside a ScrollView

Found the solution myself in the end. The problem was not with the LinearLayout, but with the ScrollView (seems weird, considering the fact that the ScrollView was expanding, while the LinearLayout wasn't).

The solution was to use android:fillViewport="true" on the ScrollView.

Linear Layout does not expanding in ScrollView

android:weightSumwill not work inside ScrollView. That's the whole point of using ScrollView to contain all elements vertically even outside of height bound.
Set android:fillViewport="true" in ScrollView to make it work . This will make the content to fill ViewPort.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_home"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent"
android:orientation="vertical"
>
</ScrollView>

This is equivalent to using a LinearLayout so why don't just remove ScrollView and LinearLayout with weightSum.

LinearLayout not scrolling with ScrollView

Try changing android:layout_width="wrap_content" to android:layout_width="match_parent"

<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="61dp"
android:orientation="vertical" >
</LinearLayout>

</ScrollView>

Android ScrollView not srcoll inside LinearLayout

Now scrollview is working. Code down below

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/startActivityRootLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:background="@color/dark_cyan"
tools:context="com.geodevteam.geopay.project.activity.StartActivity">

<LinearLayout
android:orientation="vertical"
android:id="@+id/startActivityTopLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@color/dark_cyan">

<ImageView
android:id="@+id/startActivityLogoImageView"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:src="@mipmap/ico"/>

<TextView
android:id="@+id/startActivityLogoTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
style="@style/ApplicationNameTextView"
android:text="@string/application_title"/>

<AutoCompleteTextView
android:id="@+id/startActivityAutocompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
style="@style/AutocompleteTextViewTextColor"
android:hint="@string/start_to_input_name"/>

</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:id="@+id/startActivityBottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_alignParentBottom="true"
android:background="@color/dark_cyan">

<Button
android:id="@+id/startActivitySocialsButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/login_by_mail_button"
style="@style/LoginByMailButton"
android:text="@string/login_sign_using_social" />

<Button
android:id="@+id/startActivityEmailButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/login_by_mail_button"
style="@style/LoginByMailButton"
android:text="@string/login_using_mail" />

</LinearLayout>

<LinearLayout
android:id="@+id/startActivityCenterLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/startActivityBottomLayout"
android:layout_below="@id/startActivityTopLayout"
android:background="@color/dark_cyan">

<ScrollView
android:id="@+id/startActivityCenterLayoutScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<RelativeLayout
android:id="@+id/cardsRootLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">

</RelativeLayout>

</ScrollView>

</LinearLayout>

</RelativeLayout>

LinearLayout Inside of ScrollView doesn't expand

If you want to scroll horizontally you should probably use HorizontalScrollView instead of ScrollView



Related Topics



Leave a reply



Submit