Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove flickering on actionbar hiding/unhiding

My app has a listview and I want to hide the actionbar when I scroll down and unhide the actionbar when I scroll up.The problem is not the hiding/unhiding of the action bar but the flickering that is happening due to this.

I googled a lot and the closet thing to a solution I found is this: StackOverflow Question

According to the solution given: I have to add a paddingTop of listview of height equal to actionbar's height, then add a header.

So, I set the padding at the top of the listview with height of "?android:attr/actionBarSize" but I am stuck at what to do next. What will be the content 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 is doing is adding a permanent padding on top of listview so how will adding a header solve my flickering problem.

Or is there any other way to solve this problem?

Thanks.

like image 657
Mohit Avatar asked Dec 23 '14 07:12

Mohit


People also ask

How to hide the action bar in Android app?

Another way to hide Action Bar is through Window Manager by setting the WindowManager flag. This approach makes it a lot easier to hide the Action Bar when the user interacts with your application. You can use the “setFlags” function as described below in the code. Also, you have to use flags before setContentView () of Activity.

How do I fix a flickering screen on Windows 10?

How to troubleshoot screen flickering. The first thing you need to do is to figure out what's actually causing the screen to flicker. You can quickly find this out by opening the Task Manager by right-clicking the Taskbar and selecting Task Manager, or you can use the Ctrl + Shift + Esc keyboard shortcut.

Why is Task Manager flickering in Windows 10?

In the case that Task Manager flickers along with everything else on the screen, then the problem is most likely to be the graphics drivers. Once you've figured out what is generally causing the issue you went through the troubleshooting steps, you can follow the steps below to tackle the problem.

How do I get teams to stop flashing in the taskbar?

How Do I Get Teams to Stop Flashing in the Taskbar? If Teams is flashing in your taskbar, try editing your Registry. More specifically, edit the ForegroundFlashCount key and set it to 1. In this manner, the Teams icon will only flash once. Keep in mind that setting the ForegroundFlashCount value to zero won’t stop the flashing.


1 Answers

I don't know why you need header to get rid from flickering. The idea is that when you add

 requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

listview is drawn underneath the ActionBar, thats why its layout doesn't change when actionbar hiding. To prevent content from overlapping by ActionBar when screen is opened you can add clipToPadding attribute:

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

EDITED: I get it, you need header to simulate top padding.

like image 60
Bracadabra Avatar answered Oct 15 '22 06:10

Bracadabra