Android的动作条隐藏/显示滚动列表视图时 [英] Android ActionBar hide/show when scrolling list view

查看:129
本文介绍了Android的动作条隐藏/显示滚动列表视图时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想隐藏/显示兼容性操作栏为用户滚动向上/向下列表视图。当动作栏消失的名单也占据了操作栏的空间。

我已经按照一种方法,但它会产生一个丑陋的闪烁。有没有人有这个问题妥善解决?所需的行为就像在Google+应用隐藏/显示机制(我没兴趣对页脚)。

我已经试过低于psented $ P $:

 布尔tabletSize = getResources()getBoolean(R.bool.isTablet)。
    如果(!tabletSize){
        最后动作条的ActionBar =((ActionBarActivity)getActivity())getSupportActionBar()。
        lvNews.setOnScrollListener(新AbsListView.OnScrollListener(){
            私人诠释mLastFirstVisibleItem;

            @覆盖
            公共无效onScrollStateChanged(AbsListView观点,诠释scrollState){
            }

            @覆盖
            公共无效onScroll(AbsListView观点,诠释firstVisibleItem,
                                 INT visibleItemCount,诠释totalItemCount){

                如果(mLastFirstVisibleItem< firstVisibleItem){
                    如果(actionBar.isShowing()){
                        actionBar.hide();
                    }
                }

                如果(mLastFirstVisibleItem> firstVisibleItem){
                    如果(!actionBar.isShowing()){
                        actionBar.show();
                    }
                }
                mLastFirstVisibleItem = firstVisibleItem;
            }
        });
    }
 

解决方案

要避免因您可以使用覆盖属性的操作栏布局的调整闪烁。

https://developer.android.com/training/basics/actionbar/ overlaying.html

但这种方法会导致操作栏中覆盖你的ListView,所以你需要添加页眉这一尺寸:

机器人:ATTR / actionBarSize

例如:

  mVideosListView =(ListView控件)getActivity()findViewById(android.R.id.list)。
mVideosListView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.listview_header,null));
 

注意与其他元素,如导航抽屉这也是受此影响。

I want to hide/show the compatibility action bar as the user scrolls up/down a listview. When the action bar disappears the list will occupy also the action bar's space.

I've followed an approach but it generates an ugly flickering. Does anyone have a proper solution for this problem? The desired behaviour is like the hide/show mechanism in the Google+ app (I'm not interested about the footer).

What I've tried is presented below:

boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
    if (!tabletSize) {
        final ActionBar actionBar = ((ActionBarActivity) getActivity()).getSupportActionBar();
        lvNews.setOnScrollListener(new AbsListView.OnScrollListener() {
            private int mLastFirstVisibleItem;

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem,
                                 int visibleItemCount, int totalItemCount) {

                if (mLastFirstVisibleItem < firstVisibleItem) {
                    if (actionBar.isShowing()) {
                        actionBar.hide();
                    }
                }

                if (mLastFirstVisibleItem > firstVisibleItem) {
                    if (!actionBar.isShowing()) {
                        actionBar.show();
                    }
                }
                mLastFirstVisibleItem = firstVisibleItem;
            }
        });
    }

解决方案

To avoid the flickering caused by the readjustment of the layout you can use the overlaying property in the action bar.

https://developer.android.com/training/basics/actionbar/overlaying.html

But this solution causes that the action bar overlays your listview, so you need to add a header with this size:

"?android:attr/actionBarSize"

for example :

mVideosListView = (ListView) getActivity().findViewById(android.R.id.list);
mVideosListView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.listview_header,null));

Be careful with other elements like navigation drawer which is also affected by this.

这篇关于Android的动作条隐藏/显示滚动列表视图时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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