Quentin
Quentin

Reputation: 1781

How to scroll programatically a ScrollView?

I have a little problem with a ScrollView. I have a layout for an activity which is made with a ScrollView. This scrollview contains two ListViews.

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootViewGroup" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="vertical">

<LinearLayout android:orientation="vertical"
    android:gravity="top" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:background="@drawable/cmb_bg">

    <ListView android:id="@+id/accountsListView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:scrollbars="none" />

    <ListView android:id="@+id/cardsListView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:scrollbars="none" />

</LinearLayout>

In the onCreate method of my activity I compute ListViews height according their contents.

During execution, on activity launch, ScrollView is already scrolled a bit.

So I tried, at the end of onCreate to call method scrollTo(0, 0), but it does not change anything.

Any ideas?

Upvotes: 0

Views: 2388

Answers (1)

Alex Volovoy
Alex Volovoy

Reputation: 68444

AHHH!!! Remove ScrollView and leave only ONE ListView in your activity. It's not intended to work this way .If you want to have different content in your ONE listView - modify your adapter, or change the UI But never, ever put different scrollable containers on the same screen/inside each other here is a related post. http://groups.google.com/group/android-developers/browse_thread/thread/e7c8df374fe31733# In theory you can slap two listview on the screen, but expect things to be weird. And i would really redesign it with with either separators or expanders or just with one ListView.

Upvotes: 6

Related Questions