1

I can't make a ScrollView properly scrolling. It always cut off the content on the bottom, as if it were a normal LinearLayout.

My code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:layout_width="fill_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:context="com.android.dadiperpus.MainActivity">

I put LinearLayout inside ScrollView

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/logo_stan"
    android:orientation="vertical"
    android:weightSum="10">

Then I put RelativeLayout inside LinearLayout

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_horizontal|center_vertical"
            android:text="CONTOH BRO"
            android:textSize="32sp" />
    </RelativeLayout>

Here I use Gridlayout

    <GridLayout
        android:id="@+id/mainGrid"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="8"
        android:alignmentMode="alignMargins"
        android:columnCount="2"
        android:columnOrderPreserved="false"
        android:padding="14dp"
        android:rowCount="3">

Then I put couple of this code inside GridLayout

        <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_rowWeight="1"
            app:cardCornerRadius="8dp"
            app:cardElevation="8dp">
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:orientation="vertical">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:src="@drawable/logo_stan" />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Pengantar Kepabeanan"
                    android:textAlignment="center"
                    android:textColor="@android:color/black"
                    android:textSize="18sp"
                    android:textStyle="bold" />
            </LinearLayout>
        </android.support.v7.widget.CardView>

I already tried to wrap ScrollView inside LinearLayout and it didn't change anything at all.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

1

I put LinearLayout inside ScrollView

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/logo_stan"
    android:orientation="vertical"
    android:weightSum="10">

This linearlayout needs to use wrap_content for its height. By using match_parent, you're saying you want the linearlayout to only be as tall as the scrollview that's hosting it... which means it will cut off all the "scrollable" content. By using wrap_content (or some fixed height that's larger than the scrollview) you will have more content in the linearlayout than is visible on one screen, and then scrolling will work as expected.

Ben P.
  • 52,661
  • 6
  • 95
  • 123
0

On removing weightsum from Linear Layout, layout_weight from Relative Layout and Grid Layout , your scrollview will scroll (only in case if content is more than screen size). Give height to all these layouts ( Relative Layout and Grid Layout) wrap_content instead of 0dp. Actually what happen in your code is : You have given Linear Layout's height match_parent (equal to screen size) and weightsum 10. And Then you give Relative Layout layout_weight = 2 and grid layout's layout_weight = 8 which means relative layout is taking 2 parts of screen and grid layout is taking 8 parts of screen. In this case, your content will never grow more than scree size and grid layout try to fit in screen due to which, your content get cut off at bottom.

Hope, It will help you.

Thanks

Parul
  • 387
  • 1
  • 5