当前位置:首页 > 移动开发 > Android

andorid 向上滑动统制标题栏显示

优良自学吧提供andorid 向上滑动统制标题栏显示,andorid 向上滑动控制标题栏显示要实现这样的功能,原理不难,监听滑动距离再设置标题栏的透明度 下面是监听一个带头view的list实现核心代码: mbar是标题栏 mListView.setOnScrollListener(new AbsListView.OnScro

andorid 向上滑动控制标题栏显示

要实现这样的功能,原理不难,监听滑动距离再设置标题栏的透明度

下面是监听一个带头view的list实现核心代码:

mbar是标题栏

 mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
            }

            @Override
            public void onScroll(AbsListView listView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                if (visibleItemCount == 0) {
                    return;
                }

                int[] location = new int[2];
                mIvBusinessLogo.getLocationOnScreen(location);

                int mgTop = location[1] - getNotificationBarHeight() - mBar.getHeight();

                if (mgTop > 3) {
                    int top = -mgTop;
                    int headerHeight = mIvBusinessCover.getHeight() - mBar.getHeight();
                    if (top <= headerHeight) {
                        float f = (float) top / (float) headerHeight;
                        int alpha = (int) (f * 255);
//                        Log.i("wg", "alpha = " + alpha);
                        if (alpha < -255) {
                            alpha = -255;
                        }
                        mBar.setTitleBarAlpha(alpha);
                    }
                } else {
                    mBar.setTitleBarAlpha(255);
                }
            }
        });
    }

 

    private int getNotificationBarHeight() {
        if (notificationBarHeight == 0) {
            Rect rect = new Rect();
            this.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);

            notificationBarHeight = rect.top;
        }

        return notificationBarHeight;
    }

 


(本文来自互联网,不代表搜站(http://www.ylzx8.cn/)的观点和立场)
本站所有内容来自互联网,若本站收录的信息无意侵犯了贵司版权,请给我们来信(ylzx8cn@163.com),我们会及时处理和回复,谢谢