0

Here's the Layout xml file:

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

    <LinearLayout
        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="factory.Settings"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:orientation="vertical">

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

            <TextView
                android:id="@+id/lblShopID"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/ShopId"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText
                android:id="@+id/txtShopID"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:layout_weight="1" />

        </LinearLayout>

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

            <TextView
                android:id="@+id/lblShopname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/lblShopID"
                android:layout_marginTop="36dp"
                android:text="@string/ShopName"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <Spinner
                android:id="@+id/spinShopName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/lblShopname"
                android:layout_toRightOf="@+id/lblShopname" />
        </LinearLayout>

        <Button
            android:id="@+id/btnSaveChanges"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/spinShopName"
            android:layout_marginTop="22dp"
            android:onClick="saveData"
            android:text="Save Changes" />

        <TextView
            android:id="@+id/txtChangePassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:text="@string/ChangePassword"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_marginTop="30px" />

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="30px">

            <TextView
                android:id="@+id/lblOldPassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/OldPassword"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText
                android:id="@+id/txtOldPassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="textPassword" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/lblNewPassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/NewPassword"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText
                android:id="@+id/txtNewPassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="textPassword" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/lblRetypePassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/RetypePassword"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText
                android:id="@+id/txtRetypePassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="textPassword" />
        </LinearLayout>

        <Button
            android:id="@+id/btnChangePassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="changePassword"
            android:text="Change Password" />

        <ListView
            android:id="@+id/lstUsers"
            android:layout_width="340dp"
            android:layout_height="wrap_content" />
    </LinearLayout>
</ScrollView>

And Here's the expecting output: enter image description here

The expected output is : I have some items in lstUsers and there wouldn't be enough space for displaying all the users, so I would like to add a scrollview to the Layout to let users scroll down.

But the problem is: the scrollview doesn't wrap any controls at all, the outcome is:

enter image description here

As you can see, the scrollview is unable to wrap the lstUser

Is there anything wrong with the layout file?

User2012384
  • 4,769
  • 16
  • 70
  • 106

2 Answers2

1

I don't think you are allowed to put a listview in a scrollview. Listview implements its own scroller so it doesn't like being in a scrollview. Take a look at this link

How can I put a ListView into a ScrollView without it collapsing?

Community
  • 1
  • 1
James Russo
  • 578
  • 3
  • 18
1

Scrollview and Listview do not work well with each other.

What I would suggest u is to make 'lstUsers' Listview the main content of the layout file.

Create a separate layout file with the views that are above the listview.

Then inflate this layout file and add it as a header view to the listview.

vishnus
  • 728
  • 2
  • 7
  • 20