Andorid sliding up control title bar display, andorid title bar

Source: Internet
Author: User

Andorid sliding up control title bar display, andorid title bar

To implement this function, it is not difficult to define the principle. Listen to the sliding distance and then set the transparency of the title bar.

The following is the core code for listening to a list of leading views:

Mbar is the title bar.

 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;    }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.