0

I have a main ScrollView and then I have a child LinearLayout and that has ListView in it. I'm not sure why it is not scrolling. I read about how listview should not be inside scroll view, but I need my layout to scroll and then view the listview. I'm not sure if this is the proper approach. Please direct.

This works on my tablet with a large screen but not on my phone which has a smaller screen and you need to scroll to view the listview completely. The listview works if I use linear layout but then I don't see the listview completely because its on the bottom of the layout.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fitsSystemWindows="true" >

<LinearLayout
    android:id="@+id/user_info"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:paddingTop="46dp"
    android:paddingLeft="24dp"
    android:paddingRight="24dp" >

    <Spinner
        android:id="@+id/userTypeSpinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp" />

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp">
        <EditText android:id="@+id/fname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:hint="First Name"/>
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp" >
        <EditText android:id="@+id/lname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:hint="Last Name"/>
    </android.support.design.widget.TextInputLayout>

    <LinearLayout
        android:id="@+id/staff_username"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:visibility="gone" >

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp" >
            <EditText android:id="@+id/uname"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:hint="Username"/>
        </android.support.design.widget.TextInputLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/staff_password"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:visibility="gone" >

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp" >
            <EditText android:id="@+id/upassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:hint="Password"/>
        </android.support.design.widget.TextInputLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/staff_email"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:visibility="gone" >

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp" >
            <EditText android:id="@+id/uemail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:hint="Email"/>
        </android.support.design.widget.TextInputLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/staff_permissions"
        android:layout_marginTop="8dp"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="gone"
        >

        <ListView
            android:id="@+id/permission_list"
            android:layout_width="fill_parent"
            android:layout_height="200dp"
            android:fadeScrollbars="false"
            />

    </LinearLayout>

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/addUserBtn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        android:layout_marginBottom="24dp"
        android:padding="12dp"
        android:text="@string/add_new_user"/>

</LinearLayout>

Pete
  • 754
  • 2
  • 13
  • 27
  • 4
    Possible duplicate of [Android list view inside a scroll view](http://stackoverflow.com/questions/18367522/android-list-view-inside-a-scroll-view) – Shabbir Dhangot Mar 03 '16 at 04:10
  • You should not use ScrollView. Without ScrollView it will work. – Usman Mar 03 '16 at 04:14
  • It does work without it, but you cannot see it fully because the screen is small, thats why I was using scrollview to scroll down the layout – Pete Mar 03 '16 at 04:15
  • @user2698566 You can use NestedScrollView it supports both a nested scrolling parent and child http://developer.android.com/intl/ja/reference/android/support/v4/widget/NestedScrollView.html – Piyush Malaviya Mar 03 '16 at 05:00
  • see that http://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android – Kishan patel Mar 03 '16 at 06:02

2 Answers2

0

Same problem i had. This is my code. Check it out.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/login_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/login"
    android:gravity="center"
    android:orientation="vertical" >

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

        <LinearLayout
            android:layout_width="250dp"
            android:layout_height="270dp"
            android:layout_marginTop="40dp"
            android:gravity="center"
            android:orientation="vertical" >

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/username_login" />

                <EditText
                    android:id="@+id/username_login"
                    android:layout_width="200dp"
                    android:layout_height="30dp"
                    android:background="@drawable/edit_text"
                    android:inputType="text"
                    android:paddingLeft="5dp"
                    android:paddingTop="2dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/password_login" />
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

Don't use scrollview as a parent. Just take scrollview inside parent layout i.e. LinearLayout or RelativeLayout.

Däñish Shärmà
  • 2,891
  • 2
  • 25
  • 43
0

Try to replace your ListView with LinearLayout and add same items(views) in this which you want to add in your listview

PpL
  • 21
  • 7