0
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:orientation="vertical" >

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

        <RelativeLayout
            android:id="@+id/relativeLayout2"
            android:layout_width="fill_parent"
            android:layout_height="600dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true" >

            <include
                android:id="@+id/include1"
                android:layout_width="fill_parent"
                android:layout_height="70dp"
                layout="@layout/header_history" >
            </include>

            <ListView
                android:id="@android:id/list"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:cacheColorHint="#00000000"
                android:divider="@android:color/black"
                android:dividerHeight="1.0sp"
                android:textColor="#000000" />
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

header_history

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/button" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/button"
        android:gravity="left|center_vertical"
        android:text="   History"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:textStyle="bold" />

</RelativeLayout>

I am trying to make my list view scrollable but it has become scrollable but I am unable to find the details of the list view. Please help me for the same. Friends,I have updated the header_history file also.

2 Answers2

0

I've answered a question similar to this only. Here i explain you about why its not scrolling?

Simply, remove the ScrollView from your layout. And, make the LinearLayout as parent. And, try to run your app. It will scroll the list.

Because the ListView class implements its own scrolling and it just doesn't receive gestures because they all are handled by the parent ScrollView I strongly recommend you to simplify your layout somehow. For example you can add views you want to be scrolled to the ListView as headers or footers.

Have a look at this

See my existing answer

Community
  • 1
  • 1
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
0

The problem is that you put a ListView in a ScrollView. The Android API says you should never ever put a scrollable element in another scrollable element.

If you need to to this anyway, you can solve the problem by subclassing the ListView and overwriting the onMeasure() method.

Edit: You use the following code to create a fully expanded list. Also it's worth to notice, that this might be a horrible idea for large list, due to performance reasons.

public class FullExpandedListView extends ListView {

    public FullExpandedListView(Context context) {
        super(context);
    }

    @Override
    protected void onMeasure(int a, int b) {
        super.onMeasure(a, b);

        setListViewHeightBasedOnChildren();
    }

    private void setListViewHeightBasedOnChildren() {

        SwfListAdapter listAdapter = (SwfListAdapter) getAdapter();

        if (listAdapter == null) {

            return;
        }

        int totalHeight = 0;
        int desiredWidth = MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST);

        for (int i = 0; i < listAdapter.getCount(); i++) {

            View listItem = listAdapter.getView(i, null, listControl);
            listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listControl.getLayoutParams();
        params.height = totalHeight + (listControl.getDividerHeight() * (listAdapter.getCount() - 1));
        setLayoutParams(params);
    }
}
Community
  • 1
  • 1
Shelm
  • 91
  • 4
  • I have added header inside it also I need to make that header scrollable it is coming like a constant part –  Sep 06 '12 at 10:07
  • By overwriting the `onMeasure` method of the listview you can force the listview to always expand to its full size. In result the scrollview will properly handle the scrollevents again and should scroll your list and your header at the same time. – Shelm Sep 06 '12 at 10:42