3

In my application I have some buttons and one list view with different layouts and the list view is in the last position.

My problem is I attached the ScrollView as root layout so scrolling is done correctly. But the ListView visible only one list item and not scrolled.

Layout:

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/taskscrollviewid"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:scrollbars="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            android:weightSum="2" >

            <Button
                android:id="@+id/txtdate"
                android:layout_width="0dip"
                android:layout_height="30px"
                android:layout_weight="1"
                android:background="@drawable/taskbuttonselector" />

            <Button
                android:id="@+id/btnTaskTimeid"
                android:layout_width="0dip"
                android:layout_height="30px"
                android:layout_weight="1"
                android:background="@drawable/taskbuttonselector" />
        </LinearLayout>

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal" >

            <EditText
                android:id="@+id/txtItem"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/edittextselector"
                android:drawableEnd="@drawable/inbox"
                android:gravity="top|left"
                android:hint="Enter task"
                android:inputType="textMultiLine"
                android:maxLines="5"
                android:minLines="3"
                android:scrollbars="vertical"
                android:singleLine="false" />

            <ImageButton
                android:id="@+id/imagebuttonid"
                android:layout_width="31dp"
                android:layout_height="36dp"
                android:layout_gravity="right|bottom"
                android:background="@drawable/inbox" />
        </FrameLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            android:weightSum="2" >

            <Button
                android:id="@+id/btnaddcategoryid"
                android:layout_width="0dip"
                android:layout_height="30px"
                android:layout_weight="1"
                android:background="@drawable/taskbuttonselector"
                android:text="AddCategory" />

            <Button
                android:id="@+id/btnaddseverityid"
                android:layout_width="0dip"
                android:layout_height="30px"
                android:layout_weight="1"
                android:background="@drawable/taskbuttonselector"
                android:text="AddSeverity" />
        </LinearLayout>

        <Button
            android:id="@+id/btnadddb"
            android:layout_width="250px"
            android:layout_height="30px"
            android:layout_gravity="center|center_horizontal"
            android:layout_marginTop="10dp"
            android:background="@drawable/taskbuttonselector"
            android:text="Add This Task" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            android:weightSum="2" >

            <Button
                android:id="@+id/fillbut"
                android:layout_width="0dip"
                android:layout_height="30px"
                android:layout_weight="1"
                android:background="@drawable/taskbuttonselector"
                android:text="Remain Task" />

            <Button
                android:id="@+id/remainbut"
                android:layout_width="0dip"
                android:layout_height="30px"
                android:layout_weight="1"
                android:background="@drawable/taskbuttonselector"
                android:text="Finish Task" />
        </LinearLayout>

        <ListView
            android:id="@+id/listid"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:clickable="true"
            android:orientation="vertical" >
        </ListView>
    </LinearLayout>

</ScrollView>
Sparky
  • 98,165
  • 25
  • 199
  • 285
Satheesh
  • 1,722
  • 25
  • 35
  • 3
    using listview in scrollview is one of the top sins in Android development, remove it out, quickly, and place it outside scrollview – Onur A. Jul 08 '13 at 12:20
  • please have a look at this answer [enter link description here][1] [1]: http://stackoverflow.com/questions/17524319/hidden-listview-not-showing-all-elements/17524551#17524551 – farrukh Jul 08 '13 at 12:23
  • http://stackoverflow.com/questions/17449391/scroll-view-is-not-working-in-list-view/17449541#17449541/ check thuis – Raghunandan Jul 08 '13 at 12:28
  • Any luck? please try my answer it should work.. – Manish Srivastava Jul 08 '13 at 12:32
  • Just add header views in `ListView`, I think that's what you are looking for. And please please for every body's sake don't ever ... I mean EVER !! do what some of the answers are suggesting... – M-Wajeeh Jul 08 '13 at 12:36

4 Answers4

2

Add

android:layout_marginLeft="10dp"
android:layout_height = "200dp"

to your ListView

likeitlikeit
  • 5,563
  • 5
  • 42
  • 56
OMAK
  • 1,031
  • 9
  • 25
  • This is not a proper answer.. I dont know why he gave you correct answer mark.. Its just a static code lol check my answer – Ahmad Arslan Jun 02 '15 at 11:26
1

just create a class

public class Utility {
public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter(); 
    if (listAdapter == null) {
        // pre-condition
        return;
    }

    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
}
}

and then in your activity,after setting the adapter,please write the following

Utility.setListViewHeightBasedOnChildren(yourListview);
taruna
  • 61
  • 3
  • Nooooo... Don't do this... Seriously never do this... Sooner or later device will go out of memory. The whole purpose of `ListView` is set on fire if you do this. – M-Wajeeh Jul 08 '13 at 12:38
0

There is a conflict between the ScrollView and the ListView. In general, you cannot put a ListView inside a ScrollView. ListView already understands about scrolling and will scroll itself.

I faced the same problem days before. Here is my Question ScrollView distrubing ListView inside of LinearLayout

After this Answer by @David Wasser I reconsider my layout design.

Community
  • 1
  • 1
Ahmed Nawaz
  • 1,634
  • 3
  • 21
  • 51
0

The simplest solution.. only give padding to the bottom

<ListView
                android:id="@+id/lv_Jobs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:checkMark="?android:attr/listChoiceIndicatorMultiple"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"
                android:smoothScrollbar="true"
                 android:paddingBottom="50dp"
                android:textColor="#000000" />
Ahmad Arslan
  • 4,498
  • 8
  • 38
  • 59