Giter Site home page Giter Site logo

stickydemo's Introduction

StickyDemo

三步实现控件悬浮 之前做项目的时候实现的一个悬浮效果,如图(可能不够清晰) meibei.gif 接下来就是实现效果,如图所示 sticky.gif demo直接用的截图

原理很简单,用RecyclerView addHeaderView的方式实现,实现步骤:

1.添加依赖

 compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.14'
 compile 'com.android.support:recyclerview-v7:25.1.0'

导入BaseRecyclerViewAdapterHelper,用于RecyclerView添加HeaderView;

2.布局,用标签include,写入需要悬浮的view;主界面用帧布局FrameLayout

<FrameLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent">
       <android.support.v7.widget.RecyclerView
           android:id="@+id/main_recycler"
           android:layout_width="match_parent"
           android:layout_height="match_parent"/>
    <include layout="@layout/include_header_product"/>
   </FrameLayout> 
	 ```;
然后布局headerView

```

3.逻辑,滑动的时候,对RecyclerView进行滑动监听然后在onScrollStateChanged(RecyclerView recyclerView, int newState)方法里监听悬浮View在 屏幕上Y轴位移,在onScrolled(RecyclerView recyclerView, int dx, int dy)里不停的获取headerView里面悬浮标签在屏幕上Y轴位移, 进行判断悬浮view的显示或隐藏 if (mHeaderView == null) return; int getTop = mHeaderView.getDistanceY(); if (getTop <= imageY) { mImageView.setVisibility(View.VISIBLE); } else { mImageView.setY(0); mImageView.setVisibility(View.GONE); }

简书地址

apk下载

stickydemo's People

Contributors

wobiancao avatar

Watchers

James Cloos avatar peihua 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.