android - Removing flickering when hiding/showing toolbar -


my app uses toolbar hides or shows when user scrolls listview. there seems werd issue, when scrolling toolbar flickers. tried dig more information , unfortunately not able fix issue. listview located inside fragment. if have ideas or me provide more information please let me know. thank you!

mainactivity:

import android.support.v4.view.gravitycompat; import android.support.v4.widget.drawerlayout; import android.support.v7.app.actionbardrawertoggle; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar;  protected void oncreate(bundle savedinstancestate) {         requestwindowfeature(window.feature_action_bar_overlay);//does not solve flickering super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar); // code create fragments 

fragment:

public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) { //populate list code  newslist.setonscrolllistener(new onscrolllistener() {             int mlastfirstvisibleitem = 0;              @override             public void onscrollstatechanged(abslistview view, int scrollstate) {              }              public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount){                 if (view.getid() == newslist.getid()) {                          final int currentfirstvisibleitem = newslist.getfirstvisibleposition();                          if (currentfirstvisibleitem > mlastfirstvisibleitem) {                              if (((appcompatactivity) getactivity()).getsupportactionbar().isshowing()) {                                 ((appcompatactivity) getactivity()).getsupportactionbar().hide();                             }                          } else if (currentfirstvisibleitem < mlastfirstvisibleitem) {                              if (!((appcompatactivity) getactivity()).getsupportactionbar().isshowing()) {                                 ((appcompatactivity) getactivity()).getsupportactionbar().show();                             }                          }                           mlastfirstvisibleitem = currentfirstvisibleitem;                  }               }           }); 

xml:

       <listview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/listitems"         android:layout_centervertical="true"         android:layout_centerhorizontal="true"         android:layout_alignparenttop="true"         android:paddingtop="?android:attr/actionbarsize"         android:cliptopadding="false"         android:scrollbarstyle="outsideoverlay"/> 

xml called in main activity:

<android.support.v7.widget.toolbar android:id="@+id/toolbar"             android:layout_width="match_parent" android:layout_height="?attr/actionbarsize"             android:background="?attr/colorprimary" app:popuptheme="@style/apptheme.popupoverlay"/> 


Comments