Code Monkey home page Code Monkey logo

homepage's Introduction

HomePage

高仿京东商城首页,下拉刷新搜索栏隐藏,上滑渐变

图片效果

效果图

思路

  • 渐变:监听RecyclerView的滑动距离,改变搜索栏的alpha值
  • 隐藏:下拉刷新时隐藏搜索栏

##主要代码

渐变

int mDistanceY=0;
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            //滑动的距离
            mDistanceY += dy;
            //toolbar的高度
            int toolbarHeight = searchView.getBottom();
            //当滑动的距离 <= toolbar高度的时候,改变Toolbar背景色的透明度,达到渐变的效果
            if (mDistanceY <= toolbarHeight) {
                float scale = (float) mDistanceY / toolbarHeight;
                float alpha = scale * 255;
                searchView.setBackgroundColor(Color.argb((int) alpha, 255, 255, 255));
            } else {
                //将标题栏的颜色设置为完全不透明状态
                searchView.setBackgroundResource(R.color.white);
            }
        }
    });

homepage's People

Contributors

doutuifei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.