Search code examples
androidxmlandroid-layoutscrollview

Couldn't scroll all the way up in scroll view


Okay so there is this list of checkboxes in a cardview which under a LinearLayout. and I've added a scrollview since it can't fit all of them and I want to add a slider later on. But the problem is that I can't get it to scroll all the way up as seen in the picture below.I have tried a few solutions like android:fillViewport="true" given in online forums and certain sites, but none of them seems to be working.

picture

Page_three.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="top"
    android:fadeScrollbars="true"
    android:fillViewport="true"
    android:scrollbars="vertical">

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        style="@style/CardStyle.Home"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include layout="@layout/pref_check" />
    </android.support.v7.widget.CardView>

</ScrollView>

Pref_check.xml

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingTop="@dimen/view_spacing_small"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/preferences"
        android:textAppearance="@style/TextStyle.Title" />

    <CheckBox
        android:id="@+id/chkBeach"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/beach" />

    <CheckBox
        android:id="@+id/chkBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/bar" />

    <CheckBox
        android:id="@+id/chkMuseum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/museum" />

    <CheckBox
        android:id="@+id/chkRestaurant"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/restaurant" />

    <CheckBox
        android:id="@+id/chkNightClub"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/night_club" />

    <CheckBox
        android:id="@+id/chkArtGallery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/art_gallery" />

    <CheckBox
        android:id="@+id/chkAmusementPark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/amusement_park" />

    <CheckBox
        android:id="@+id/chkCasino"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/casino" />

    <CheckBox
        android:id="@+id/chkClothingStore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/clothing_store" />

    <CheckBox
        android:id="@+id/chkShoppingMall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/shopping_mall" />

    <CheckBox
        android:id="@+id/chkAmusementCenter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/amusement_center" />

    <CheckBox
        android:id="@+id/chkResort"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/Resort" />
</LinearLayout>

Activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <FrameLayout
        android:id="@+id/frame_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_navigation"
        android:animateLayoutChanges="true">

    </FrameLayout>



    <android.support.design.widget.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bottom_navigation"
        android:layout_alignParentBottom="true"
        app:itemBackground="@color/colorPrimary"
        app:itemIconTint="@color/white"
        app:itemTextColor="@color/white"
        app:menu="@menu/navigation"
        />




</RelativeLayout>

Solution

  • Solved it :

    Instead of adding the cardview in the Page_three.xml , I instead wrapped it around LinearLayout in Pref_check.xml.

    Page_three.xml

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fadeScrollbars="true"
        android:fillViewport="true"
        android:scrollbars="vertical"
        android:fitsSystemWindows="true">
       <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="vertical"
           android:paddingTop="@dimen/view_spacing_small">
           <include layout="@layout/pref_check" />
    
           <include layout="@layout/slider" />
       </LinearLayout>
    </ScrollView>
    

    Pref_check.xml

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        style="@style/CardStyle.Home"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="@dimen/view_spacing_small"
        xmlns:android="http://schemas.android.com/apk/res/android">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/preferences"
            android:textAppearance="@style/TextStyle.Title" />
    
        <CheckBox
            android:id="@+id/chkBeach"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/view_spacing_medium"
            android:checked="false"
            android:onClick="onCheckboxClicked"
            android:text="@string/beach" />
              .
              .
              .
    
    </LinearLayout>
    </android.support.v7.widget.CardView>