我的 ScrollView 中有一个 ListView ,在此之前几乎有一页滚动,但是一旦我的 ListView 被填充, ScrollView 就会移动到 ListView 的顶部。我该如何解决/防止这种情况发生?
ScrollView XML:
<ScrollView
android:id="@+id/tvscrollview"
android:layout_marginTop="8.0dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
layout="@layout/a" />
<include
layout="@layout/b" />
<include
layout="@layout/c" />
<include
layout="@layout/d" />
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
我试过 sv.fullScroll(ScrollView.FOCUS_UP); 以及我的 ScrollView 中的所有内容,但它不起作用
最佳答案
我们不应该将 ListView
放在 ScrollView
中。
解决方法:当 ScrollView
由于 ListView 的 notifyDataSetChanged()
而向上/向下移动时,
然后试试,
scrollview.setEnabled(false);
listview.setFocusable(false);
adapter.notifyDataSetChanged();
scrollview.setEnabled(true);
关于java - ScrollView 中的 ListView 我的 ScrollView 移动到 ListView 的顶部。我该如何防止这种情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9386669/