J'ai essayé de mettre en œuvre le listview d'en-tête collant décrit dans le tutoriel deLorsque les listitems défilent rapidement, setOnScrollListener ne fonctionne pas
http://javatechig.com/android/listview-header-parallax-with-sticky-view-in-android
Le problème est quand je fais défiler la liste très rapide, l'en-tête doesnot déplacez-vous en haut de l'écran comme vous le souhaitez.
I essayé connectant la valeur de Topy et heroTopY dans le procédé suivant.
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
/* Check if the first item is already reached to top.*/
if (view.getFirstVisiblePosition() == 0) {
View firstChild = listView.getChildAt(0);
topY = 0;
if (firstChild != null) {
topY = firstChild.getTop();
Log.d("topY", "" + topY);
}
heroTopY = stickyViewSpacer.getTop();
Log.e("heroTopY", "" + heroTopY);
Log.d("topY,heroTopY", topY + "," + heroTopY);
stickyView.setY(Math.max(0, heroTopY + topY));
// Set the image to scroll half of the amount that of ListView
heroImageView.setY(topY * 0.5f);
}
}
La sortie du journal est:
09-01 17:35:23.692 19530-19530/com.javatechig.parallaxlistview D/topY﹕ 0
09-01 17:35:23.692 19530-19530/com.javatechig.parallaxlistview E/heroTopY﹕ 500
09-01 17:35:23.692 19530-19530/com.javatechig.parallaxlistview D/topY,heroTopY﹕ 0,500
09-01 17:35:23.856 19530-19530/com.javatechig.parallaxlistview D/topY﹕ -29
09-01 17:35:23.856 19530-19530/com.javatechig.parallaxlistview E/heroTopY﹕ 500
09-01 17:35:23.856 19530-19530/com.javatechig.parallaxlistview D/topY,heroTopY﹕ -29,500
09-01 17:35:23.873 19530-19530/com.javatechig.parallaxlistview D/topY﹕ -72
09-01 17:35:23.873 19530-19530/com.javatechig.parallaxlistview E/heroTopY﹕ 500
09-01 17:35:23.873 19530-19530/com.javatechig.parallaxlistview D/topY,heroTopY﹕ -72,500
09-01 17:35:23.892 19530-19530/com.javatechig.parallaxlistview D/topY﹕ -84
09-01 17:35:23.892 19530-19530/com.javatechig.parallaxlistview E/heroTopY﹕ 500
09-01 17:35:23.892 19530-19530/com.javatechig.parallaxlistview D/topY,heroTopY﹕ -84,500
Comme on le voit à partir de la sortie du journal de la valeur TopY se stucked à 84 et ainsi de l'en-tête. Comment résoudre ceci? Toute solution serait utile !!!
ajouter 'Log.e' au début de' onScroll' – pskink
Avec 'if (view.getFirstVisiblePosition() == 0) {}', vous déplacez votre 'stickyView' seulement lorsque vous atteignez le sommet, est ce que tu veux? – Rami
@Rami, monsieur voici le lien de la vidéo https://youtu.be/eyWDkwVnYxo. Je voulais atteindre l'en-tête ** Heading1 ** coller au sommet comme le premier élément de listview atteint le haut de l'écran, il fonctionne très bien si le défilement est fait lentement.Mais si défilement rapide la vue ** Heading1 ** ne bouge pas jusqu'au sommet!! – Nischal