简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM