2016-03-21 9 views
1

Wie kann ich, um den Artikel vor aus dem Bildschirm auf Anschlag auszuführen automatisch mit animation.Currently Scrollen mit folgendem Code funktioniert, aber es mit Scroll sehr schnell durchführen.Wie Animation Listenansicht blättern oder begrenzen die Geschwindigkeit des Scroll-

So meine Forderung ist dies mit Animation auszuführen, um Benutzer Gleiten der Listenansicht zu sehen.

Unten ist mein Code, aber ich Ergebnis bekam nicht zu erwarten.

listview.setOnScrollListener(new AbsListView.OnScrollListener() { 

      @Override 
      public void onScrollStateChanged(AbsListView view, int scrollState) { 
       if (scrollState == SCROLL_STATE_IDLE) { 
        View child = layout.getChildAt(0); // first visible child 
        Rect r = new Rect(0, 0, child.getWidth(), child.getHeight());  // set this initially, as required by the docs 
        double height = child.getHeight() * 1.0; 
        layout.getChildVisibleRect(child, r, null); 
        if (Math.abs(r.height()) != height) 
        { 
         //only smooth scroll when not scroll to correct position 
         if (Math.abs(r.height()) < height/2.0) 
         { 
          listview.postDelayed(new Runnable() { 
           @Override 
           public void run() { 
            listview.smoothScrollBy(listview.getFirstVisiblePosition(), 10000); 
           } 
          }, 500); 
         } else if (Math.abs(r.height()) > height/2.0) 
         { 
          listview.postDelayed(new Runnable() { 
           @Override 
           public void run() { 
            listview.smoothScrollBy(listview.getFirstVisiblePosition(), 10000); 
           } 
          }, 500); 
         } else 
         { 

          listview.postDelayed(new Runnable() { 
           @Override 
           public void run() { 
            listview.smoothScrollBy(listview.getFirstVisiblePosition(),10000); 
           } 
          },500); 

         } 

        } 
       } 
      } 

      @Override 
      public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 

      } 
     }); 
+0

Überprüfen Sie diese Antwort (http://stackoverflow.com/questions/5590001/android-listview-slow-down-scroll-speed) –

+0

hat überhaupt nicht funktioniert. – user8938

Antwort

0

alte Frage, aber nur als Referenz, das war für mich:

if (condition) { 
     // add stuff to begining of ListView and scroll up 
     arrayList.add(0, stuff); 
     listView.post(new Runnable() { 
      @Override 
      public void run() { 
       listView.smoothScrollToPosition(0); 
      } 
     }); 
    } else { 
     // add stuff to end of ListView and scroll down 
     arrayList.add(index, stuff); 
     listView.post(new Runnable() { 
      @Override 
      public void run() { 
       listView.smoothScrollToPosition(adapter.getCount() - 1); 
      } 
     }); 
    } 

Im Grunde nur smoothScrollToPosition statt smoothScrollBy.

Verwandte Themen