2010-01-08 111 views
0

我有一个ScrollView的小问题。我有一个用ScrollView制作的活动的布局。这个滚动视图包含两个ListViews。如何以编程方式滚动ScrollView?

<?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> 

在我的活动的onCreate方法我计算根据其内容列表视图高度。

在执行期间,在活动启动时,ScrollView已经滚动了一下。

所以我试了一下,在onCreate的最后调用方法scrollTo(0, 0),但它并没有改变任何东西。

任何想法?

回答

6

AHHH !!!删除ScrollView并在您的活动中只保留一个ListView。它不打算以这种方式工作 。如果你想在你的ONE listView中有不同的内容 - 修改你的适配器,或更改UI 但永远不要将不同的可滚动容器放在同一屏幕/彼此内部 这里是一个相关帖子。 http://groups.google.com/group/android-developers/browse_thread/thread/e7c8df374fe31733# 从理论上讲,你可以在屏幕上拍两个listview,但期望事情变得很奇怪。我真的会重新设计它与分隔符或扩展器或只是一个ListView。

+0

有一个非常好的例子,你可以弯曲和做出真正的弯曲 通过Jeff Sharkey http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android- 09 / – 2010-01-08 17:37:24