My application has a listview , and I want to hide the action bar when I scroll down and show the action bar while scrolling up. The problem is not hiding / hiding from the action bar, but the flicker that occurs because of this.
I searched a lot on googled, and here is what I found in this solution: https://stackoverflow.com/a/312960/
According to the above solution: I need to add a paddingTop from the listview height equal to the height of the action bar, and then add a title.
So, I set the registration at the top of the list with a height of "?android:attr/actionBarSize" , but I'm stuck with what to do next. What will be the contents of the header.xml file.
My code: -
MyAdapter ma = new MyAdapter(); ListView lv = (ListView)findViewById(R.id.listView); lv.setAdapter(ma); ma.notifyDataSetChanged(); //setting onScrollListener on the listview lv.setOnScrollListener(new OnScrollListener(){ private int mLast; @Override public void onScrollStateChanged(AbsListView view, int scrollState) { // TODO Auto-generated method stub } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // TODO Auto-generated method stub if(mLast<firstVisibleItem) { if(myactionbar.isShowing()) { myactionbar.hide(); } } if(mLast>firstVisibleItem) { if(!myactionbar.isShowing()) { myactionbar.show(); } } mLast=firstVisibleItem; } });
listview.xml: -
<ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="@null" android:paddingTop="?android:attr/actionBarSize" />
OnCreate (): -
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
All this makes adding a constant addition on top of the list, as adding a title solves my flickering problem.
Or is there any other way to solve this problem?
Thanks.
source share