I had the same problem, and my solution was to use listView.smoothScrollBy(distance, 0)
. It probably has a higher overhead, but it gets the job done.
Prevent overscroll in ListView
-
19-10-2022 - |
Pergunta
Running Ice-Cream Sandwich.
I have the following in my layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/caption" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:id="@+id/itemized_list" />
</LinearLayout>
Next, I populate this list using an ArrayAdapter and the following layout for list items:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bulletpoint" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/itemized_list_item_text" />
</LinearLayout>
The rendering is fine - the listview and its items are rendered to fit the screen. However, when I call listView.scrollBy
, I am able to scroll way past where the content ends and essentially go into the "outer space" without any constraints. How can I prevent this?
Nenhuma solução correta
Outras dicas
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow