Remove flicker in the hiding / hiding action bar

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.

+6
source share
2 answers

I don’t know why a heading is needed to get rid of the flicker. The idea is that when you add

  requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); 

The listview is created under the ActionBar, so its layout does not change when you hide the action bar. To prevent content from overlapping with the ActionBar when opening the screen, you can add the clipToPadding attribute:

 <ListView … android:paddingTop="?android:attr/actionBarSize" android:clipToPadding="false" android:scrollbarStyle="outsideOverlay" /> 

Editorial: I realized you need a headline to mimic the top add-on.

+5
source

Sorry for the late reply.

I faced the same problem. But I solved this problem as follows:

You should declare your toolbar below your RecyclerView or ListView and put this line in your RecyclerView or ListView:

  "android:paddingTop="?attr/actionBarSize" android:clipToPadding="false" android:scrollbarStyle="outsideOverlay"" 
0
source

Source: https://habr.com/ru/post/980071/


All Articles