Coder Social home page Coder Social logo

arcslidinghelper's Introduction

几行代码实现Android弧形滑动

使用方式:

添加依赖:

implementation 'com.wuyr:arcslidinghelper:1.0.0'

APIs:

Method Description
create(View targetView, OnSlidingListener listener) 创建实例
targetView: 圆弧滑动事件以此View的中心点为圆心
OnSlidingListener: 旋转事件回调
enableInertialSliding(boolean enable) 设置是否开启惯性滑动
setSelfSliding(boolean isSelfSliding) 设置是否自身滑动 (即接受触摸事件的View和旋转的View是否同一个对象)
setScrollAvailabilityRatio(float ratio) 设置惯性滑动的利用率 (范围:0~1, 数值越大,旋转越激进)
setOnSlideFinishListener(OnSlideFinishListener listener) 设置滚动完毕监听器
handleMovement(MotionEvent event) 处理触摸事件
updateMovement(MotionEvent event) 更新当前手指触摸的坐标,在ViewGroup的onInterceptTouchEvent中使用
updatePivotX(int pivotX) 更新圆心x坐标
updatePivotY(int pivotY) 更新圆心y坐标
abortAnimation() 停止本次滚动
release() 释放资源

简单使用示例:

    private ArcSlidingHelper mArcSlidingHelper;
    private View mView;

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

        mView = findViewById(R.id.view);
        mView.post(() -> {
            //创建对象
            mArcSlidingHelper = ArcSlidingHelper.create(mView,
                    angle -> mView.setRotation(mView.getRotation() + angle));
            //开启惯性滚动
            mArcSlidingHelper.enableInertialSliding(true);

        });
        getWindow().getDecorView().setOnTouchListener((v, event) -> {
            //处理滑动事件
            mArcSlidingHelper.handleMovement(event);
            return true;
        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //释放资源
        mArcSlidingHelper.release();
    }

Demo下载: app-debug.apk

可定制性超强的圆弧滑动组件: https://github.com/Ifxcyr/FanLayout

效果:

preview preview

arcslidinghelper's People

Contributors

wuyr 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.