Giter Site home page Giter Site logo

eszhanghome / overscrolllayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aishang5wpj/overscrolllayout

0.0 1.0 0.0 16.82 MB

简单但是强大的阻尼滚动ViewGroup

Home Page: http://blog.csdn.net/aishang5wpj/article/details/54291616

Java 100.00%

overscrolllayout's Introduction

#前言

1、这是一个可以给你的UI添加阻尼效果的自定义ViewGroup,支持包括但不限于以下控件:

  • 普通View
  • ViewPager
  • ScrollView
  • HorizontalScrollView
  • RecyclerView
  • 等等

2、可以自定义阻力大小以及阻尼方向

效果图如下:

#项目使用 要使用OverScrollLayout给你的项目加上阻尼滚动效果,整个过程只需要两个步骤:

1、在项目的attrs.xml文件中添加如下属性:

    <declare-styleable name="OverScrollLayout">
        <attr name="dampingFactor" format="float" />
        <attr name="dampingDirection">
            <flag name="left" value="0x0001" />
            <flag name="top" value="0x0010" />
            <flag name="right" value="0x0100" />
            <flag name="bottom" value="0x1000" />
        </attr>
    </declare-styleable>

2、在布局文件中引用OverScrollLayout,并分别设置dampingFactordampingDirection的值,他们的含义分别如下:

  • dampingFactor阻尼因子,值越小表示阻力越大,默认为1(即没有阻尼效果)。
  • dampingDirection阻尼方向,顾名思义,支持左、上、右、下这4种阻尼方向。

请务必注意,在xml文件中使用OverScrollLayout给你的布局添加阻尼效果时,OverScrollLayout的直接子View只能有一个!(可以参考ScrollView。)

举个栗子:

SimpleActivity.java

public class SimpleActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple);
    }

    public void onClick(View view) {
        Toast.makeText(this, "button click", Toast.LENGTH_SHORT).show();
    }
}

activity_simple.xml

<?xml version="1.0" encoding="utf-8"?>
<com.xiaohongshu.dampingscrolling.OverScrollLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:dampingDirection="left|top|right|bottom"
    app:dampingFactor="0.7">

    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_blue_light"
        android:gravity="center"
        android:onClick="onClick"
        android:text="最简单的阻尼滚动"
        android:textColor="@android:color/white" />

</com.xiaohongshu.dampingscrolling.OverScrollLayout>

这样,一个非常简单的支持四向阻尼效果的小项目就出来了!看看效果图:

#实现过程

详细实现请看博客 简单但是强大的阻尼滚动ViewGroup

关于

博客:http://blog.csdn.net/aishang5wpj

邮箱:[email protected]

License

Copyright 2017 aishang5wpj

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

overscrolllayout's People

Watchers

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