How to make scrollview extend beyond screensize android?

1.1k Views Asked by At

My root element is relative layout, within which I have one LinearLayout wrapped into a scrollview. The LinearLayout has multiple children that include textViews, editText, and other Linearlayouts that have textviews and editText. Looked into several SO posts, but no help. All I get is a grey bar on the right of the screen,which scrolls just an inch max, can't scroll any further down.The last few components are only half visible and scrolling does not happen until the bottom where my last components are visible. Setting the viewport parameter to true/false has no effect. Any help will be appreciated.

<RelativeLayout
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"
android:background="@drawable/bg_plain"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Testactivity">

<TextView
    android:id="@+id/tv_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerInParent="true"
    android:layout_marginTop="40dp"
    android:gravity="center"
    android:singleLine="true"
    android:text="INFORMATION"
    android:textAlignment="center"
    android:textColor="#6D6E71"
    android:textSize="25sp"
    />

<ScrollView
    android:layout_width="300dp"
    android:layout_height="560dp"
    android:layout_below="@+id/tv_title"
    android:layout_centerInParent="true"
    android:fillViewport="true"
    >

    <LinearLayout
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginTop="10dp"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_firstname"
                android:layout_width="170dp"
                android:layout_height="30dp"
                android:layout_gravity="left"
                android:gravity="left|center"
                android:text="FIRST NAME*"
                android:textColor="#E96F34"
                android:textSize="16sp"
                />

            <TextView
                android:id="@+id/tv_lastname"
                android:layout_width="130dp"
                android:layout_height="30dp"
                android:layout_gravity="left"
                android:gravity="left|center"
                android:text="LAST NAME*"
                android:textColor="#E96F34"
                android:textSize="16sp"
                />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/et_firstname"
                android:layout_width="130dp"
                android:layout_height="30dp"
                android:background="@drawable/orange_full_rounded_corner"
                android:gravity="center"
                android:inputType="textPersonName"
                android:maxLength="3"
                />

            <Space
                android:layout_width="40dp"
                android:layout_height="30dp"/>

            <EditText
                android:id="@+id/et_lastname"
                android:layout_width="130dp"
                android:layout_height="30dp"
                android:background="@drawable/orange_full_rounded_corner"
                android:gravity="center"
                android:inputType="textPersonName"
                />
        </LinearLayout>

        <TextView
            android:id="@+id/tv_titlein"
            android:layout_width="170dp"
            android:layout_height="30dp"
            android:layout_gravity="left"
            android:gravity="left|center"
            android:text="TITLE"
            android:textColor="#E96F34"
            android:textSize="16sp"
            />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:orientation="horizontal">

            <RadioGroup
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <RadioButton
                    android:id="@+id/cb_mr"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/orange_full_rounded_corner"
                    android:gravity="center"
                    android:text="MR."
                    />

                <Space
                    android:layout_width="30dp"
                    android:layout_height="match_parent"/>

                <RadioButton
                    android:id="@+id/cb_mrs"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/orange_full_rounded_corner"
                    android:gravity="center"
                    android:text="MRS./MS."
                    />
            </RadioGroup>
        </LinearLayout>

        <TextView
            android:id="@+id/tv_company"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_gravity="left"
            android:gravity="left|center"
            android:text="COMPANY"
            android:textColor="#E96F34"
            android:textSize="16sp"
            />

        <EditText
            android:id="@+id/et_company"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:background="@drawable/orange_full_rounded_corner"
            android:gravity="center"
            android:inputType="number"
            />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_phone"
                android:layout_width="170dp"
                android:layout_height="30dp"
                android:layout_gravity="left"
                android:gravity="left|center"
                android:text="PHONE*"
                android:textColor="#E96F34"
                android:textSize="16sp"
                />

            <TextView
                android:id="@+id/tv_mobilephone"
                android:layout_width="130dp"
                android:layout_height="30dp"
                android:layout_gravity="left"
                android:gravity="left|center"
                android:text="MOBILE PHONE*"
                android:textColor="#E96F34"
                android:textSize="16sp"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/et_phone"
                android:layout_width="130dp"
                android:layout_height="30dp"
                android:background="@drawable/orange_full_rounded_corner"
                android:gravity="center"
                android:inputType="number"
                android:maxLength="3"
                />

            <Space
                android:layout_width="40dp"
                android:layout_height="30dp"/>

            <EditText
                android:id="@+id/et_mobilephone"
                android:layout_width="130dp"
                android:layout_height="30dp"
                android:background="@drawable/orange_full_rounded_corner"
                android:gravity="center"
                android:inputType="number"
                />
        </LinearLayout>

        <TextView
            android:id="@+id/tv_emailaddress"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_gravity="left"
            android:gravity="left|center"
            android:text="EMAIL*"
            android:textColor="#E96F34"
            android:textSize="16sp"
            />

        <EditText
            android:id="@+id/et_emailaddress"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:background="@drawable/orange_full_rounded_corner"
            android:gravity="center"
            android:inputType="textEmailAddress"
            />

        <TextView
            android:id="@+id/tv_address"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_gravity="left"
            android:gravity="left|center"
            android:text="ADDRESS"
            android:textColor="#E96F34"
            android:textSize="16sp"
            />

        <EditText
            android:id="@+id/et_address"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:background="@drawable/orange_full_rounded_corner"
            android:gravity="center"
            android:inputType="text"
            />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_city"
                android:layout_width="170dp"
                android:layout_height="30dp"
                android:layout_gravity="left"
                android:gravity="left|center"
                android:text="CITY"
                android:textColor="#E96F34"
                android:textSize="16sp"
                />

            <TextView
                android:id="@+id/tv_zipcode"
                android:layout_width="130dp"
                android:layout_height="30dp"
                android:layout_gravity="left"
                android:gravity="left|center"
                android:text="ZIP CODE"
                android:textColor="#E96F34"
                android:textSize="16sp"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/et_city"
                android:layout_width="130dp"
                android:layout_height="30dp"
                android:background="@drawable/orange_full_rounded_corner"
                android:gravity="center"
                android:inputType="text"
                android:maxLength="3"
                />

            <Space
                android:layout_width="40dp"
                android:layout_height="30dp"/>

            <EditText
                android:id="@+id/et_zipcode"
                android:layout_width="130dp"
                android:layout_height="30dp"
                android:background="@drawable/orange_full_rounded_corner"
                android:gravity="center"
                />
        </LinearLayout>
    </LinearLayout>
</ScrollView>

1

There are 1 best solutions below

0
On

Your layout structure is fine. The problem is you are setting a specified height for almost everything, that's a no no. If you want to work with font height, there's a property called

android:textSize

in all views related to text, and the preferred unit is sp for text, dp for images.

Change all heights to

wrap_content