Preethi Rajan
Preethi Rajan

Reputation: 19

Scrollview not working

This is my coding i have added a toolbar and i want the data below to scroll but its scrolling entirely.I Tried many solution in SO but still its of No use.Pls check and if found any error help me

Thanks in Advance

 <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"
    tools:context="com.agna.hrm_sainmarks.Address" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/White"
        android:orientation="vertical" >

        <include
            android:id="@+id/emergencytoolbar"
            layout="@layout/emergency_toolbar" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/name"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="Ajith Kumar"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View01"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/Hrmbg" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/relationship"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primrelationship"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="Brother"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View02"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/Hrmbg" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/phone"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primphone"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="9998885231"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View03"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/Hrmbg" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/taddress"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primaddress"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="78,Muthu nagar 3rd Street,Coimbatore-44"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View04"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/Hrmbg" />
        </ScrollView>
    </LinearLayout>

</RelativeLayout>

emergency_toolbar

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


        <!-- <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:background="@color/Hrmtool"
            android:minHeight="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark"
            android:titleTextColor="@color/Red" > -->

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:textColor="@color/Black"
                android:weightSum="2"
                 >

                <Button
                    android:id="@+id/pemergency"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:clickable="@color/Hrmbg"

                    android:layout_weight="1"
                     android:textSize="18dp" 
                    android:text="@string/pemergency"
                    android:textColor="@color/Black" />

                <Button
                    android:id="@+id/semergency"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:clickable="@color/Hrmbg"

                     android:layout_weight="1"
                      android:textSize="18dp" 
                    android:text="@string/semergency"
                    android:textColor="@color/Black" />
            </LinearLayout>
       <!--  </android.support.v7.widget.Toolbar> -->


</RelativeLayout>

Upvotes: 0

Views: 6608

Answers (5)

Preethi Rajan
Preethi Rajan

Reputation: 19

The following two lines solved my problem:

android:lines="4"
android:maxLines="4"

now it's working.

Upvotes: 0

Maulik Dodia
Maulik Dodia

Reputation: 1659

You need to do just few changes.

  1. In emergency_toolbar.xml change the layout_height of RelativeLayout and LinearLayout to wrap_content.

  2. In activity_main.xml put <include.... code outside LinearLayout and Inside of RelativeLayout.

  3. You have to add LinearLayout just after ScrollView to wrap WHOLE fields as ScrollView can hold only one DIRECT CHILD.

  4. Most important point: Add too many address field as you can see SCROLL at runtime. Just copy-paste address field and change the ids field of them.

Below is screen shot, which I have got as Outcome. And See this CodeLink.

OutCom

Hope this will help.

Upvotes: 1

Salil Deshpande
Salil Deshpande

Reputation: 105

Try this, I tried to add data to it and then scrolled. The views below toolbar are being scrolled as expected:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="in.net.codestar.ratingbar.MainActivity"
    tools:showIn="@layout/activity_main">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/White"
    android:orientation="vertical" >

    <include
        android:id="@+id/emergencytoolbar"
        layout="@layout/emergency_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/name"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="Ajith Kumar"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View01"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/Hrmbg" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/relationship"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primrelationship"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="Brother"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View02"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/Hrmbg" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/phone"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primphone"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="9998885231"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View03"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/Hrmbg" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/taddress"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primaddress"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="78,Muthu nagar 3rd Street,Coimbatore-4478,Muthu nagar 3rd Street,Coimbatore-44"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View04"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/Hrmbg" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

</RelativeLayout>

emergency_toobar.xml :

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="wrap_content"
    android:layout_height="wrap_content">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:textColor="@color/Black"
    android:weightSum="2"
    >

    <Button
        android:id="@+id/pemergency"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:clickable="@color/Hrmbg"

        android:layout_weight="1"
        android:textSize="18dp"
        android:text="@string/pemergency"
        android:textColor="@color/Black" />

    <Button
        android:id="@+id/semergency"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:clickable="@color/Hrmbg"

        android:layout_weight="1"
        android:textSize="18dp"
        android:text="@string/semergency"
        android:textColor="@color/Black" />
</LinearLayout>

</RelativeLayout>

Upvotes: 0

Jay Rathod
Jay Rathod

Reputation: 11245

As Scroll View can hold only one direct child.You need to define it above Your Main Linear Layout. Also use Scroll Bars Property in Scroll View.

EDIT :

Move your Tool Bar Layout above Scroll View.

Try this code.

<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"
    tools:context="com.agna.hrm_sainmarks.Address">

    <include
        android:id="@+id/emergencytoolbar"
        layout="@layout/toolbar" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/emergencytoolbar"
        android:scrollbars="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"

            android:orientation="vertical">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/app_name"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="Ajith Kumar"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View01"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="#FFFFFF" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/app_name"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primrelationship"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="Brother"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View02"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="#FFFFFF" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="phone"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primphone"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="9998885231"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View03"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="#FFFFFF" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/app_name"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primaddress"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="78,Muthu nagar 3rd Street,Coimbatore-44"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View04"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="#FFFFFF" />

        </LinearLayout>

    </ScrollView>

</RelativeLayout>

Upvotes: 0

Ravi Makvana
Ravi Makvana

Reputation: 2902

ScrollView hold only one view as Childview try this code

<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"
tools:context="com.agna.hrm_sainmarks.Address">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/White"
    android:orientation="vertical">

    <include
        android:id="@+id/emergencytoolbar"
        layout="@layout/emergency_toolbar" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/name"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="Ajith Kumar"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View01"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/Hrmbg" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/relationship"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primrelationship"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="Brother"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View02"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/Hrmbg" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/phone"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primphone"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="9998885231"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View03"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/Hrmbg" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal"
                android:padding="5dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/taddress"
                    android:textSize="18dp" />

                <TextView
                    android:id="@+id/primaddress"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="78,Muthu nagar 3rd Street,Coimbatore-44"
                    android:textSize="18dp" />
            </LinearLayout>

            <View
                android:id="@+id/View04"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/Hrmbg" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

Upvotes: 0

Related Questions