在动作条隐藏/取消隐藏消除闪烁 [英] Remove flickering on actionbar hiding/unhiding

查看:211
本文介绍了在动作条隐藏/取消隐藏消除闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个列表视图,我想隐藏的动作条当我向下滚动并取消隐藏动作条,当我滚动理想管材的问题不是隐藏/取消隐藏操作栏,但闪烁正在发生,由于这一点。

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.

我GOOGLE了很多,衣柜里的东西的解决方案,我发现是这样的:<一href=\"http://stackoverflow.com/questions/25500353/android-actionbar-hide-show-when-scrolling-list-view\">StackOverflow问

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

根据给出的解决方案:我要补充一个 paddingTop 高度相等的列表视图到ActionBar的高度,然后添加一个头。

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

所以,我设置了填充在与的高度列表视图顶部的机器人:ATTR / actionBarSize但我停留在下一步该怎么做。会是怎样的header.xml文件的内容。

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.

我的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?

感谢。

推荐答案

我不知道为什么你需要头部摆脱闪烁去掉。这个想法是,当你添加

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控件的绘制动作条的下面,这就是为什么它的布局时不动作条隐藏更改。要当屏幕打开时您可以添加 clipToPadding 属性通过动作条重叠prevent内容:

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.

这篇关于在动作条隐藏/取消隐藏消除闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆