GithubHelp home page GithubHelp logo

mvpleung / cardslideview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from crazysunj/cardslideview

0.0 2.0 0.0 1.29 MB

一行代码实现ViewPager卡片效果,支持无限循环

License: Apache License 2.0

Java 100.00%

cardslideview's Introduction

CardSlideView

一行代码实现ViewPager卡片效果,支持无限循环,支持正常与卡片之间的切换

想实现轮播效果的同学,可以参考CrazyDaily开源项目首页实现。

效果

用法

CardViewPager viewPager = (CardViewPager) findViewById(R.id.viewpager);
viewPager.bind(getSupportFragmentManager(), new MyCardHandler(), Arrays.asList(imageArray));
public class MyCardHandler implements CardHandler<String> {

    @Override
    public View onBind(final Context context, final String data, final int position) {
        View view = View.inflate(context, R.layout.item, null);
        ImageView imageView = (ImageView) view.findViewById(R.id.image);
        Glide.with(context).load(data).into(imageView);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, "data:" + data + "position:" + position, Toast.LENGTH_SHORT).show();
            }
        });
        return view;
    }
}
//正常与卡片效果切换切换,请设置合理的值
private void switchNormal() {
    viewPager.setCardTransformer(0, 0);
    viewPager.setCardPadding(0);
    viewPager.setCardMargin(0);
    viewPager.notifyUI(CardViewPager.MODE_NORMAL);
}

private void switchCard() {
    viewPager.setCardTransformer(180, 0.38f);
    viewPager.setCardPadding(60);
    viewPager.setCardMargin(40);
    viewPager.notifyUI(CardViewPager.MODE_CARD);
}
// 获取当前下标
public int getCurrentIndex();

// 原setCurrentItem请用setCurrentIndex替代

// addOnPageChangeListener和setOnPageChangeListener回调position对应data,但data不能进行增删操作,如果要进行增删,请重新bind

详细介绍戳这里

具体参考demo

注意事项,实现Serializable的类其内嵌类也必须实现Serializable

public class A {
    B b;
    public static class B{}
}

如上,A和B都必须实现Serializable,如果不想序列化,可以在变量前面添加transient关键字,但是有小概率事件发生Activity被系统杀死重启异常问题,大家尽量不要提到成员变量处

gradle依赖

implementation 'com.crazysunj:cardslideview:1.4.2'
同时还需要依赖自己的v4包和cardview包

感谢

android-page-transition

传送门

博客:http://crazysunj.com/

谷歌邮箱:[email protected]

QQ邮箱:[email protected]

如果有什么新奇想法或者有需要优化改进的地方可以发我邮箱或者加我QQ387953660

License

Copyright 2017 Sun Jian

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.

cardslideview's People

Contributors

crazysunj avatar

Watchers

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