繁体   English   中英

如何以编程方式滚动ScrollView?

[英]How to scroll programatically a ScrollView?

我对ScrollView有一点问题。 我有一个使用ScrollView进行的活动的布局。 此滚动视图包含两个ListView。

<?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方法中,我根据其内容计算ListViews的高度。

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

因此,我尝试在onCreate的末尾调用方法scrollTo(0, 0) ,但是它没有任何改变。

有任何想法吗?

啊! 删除ScrollView并在活动中仅保留一个ListView。 如果您想在ONE listView中包含不同的内容,请修改适配器或更改UI,但是永远不要将不同的可滚动容器放在同一屏幕上/彼此内部,这是相关的文章。 http://groups.google.com/group/android-developers/browse_thread/thread/e7c8df374fe31733#从理论上讲,您可以在屏幕上拍两个listview,但希望情况会很奇怪。 我真的会使用分隔符或扩展器或仅使用一个ListView重新设计它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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