Skip to content

black4bird/SwipeCardView

Repository files navigation

SwipeCardView

Android Arsenal Platform API OSSLab

支持左右滑动操作的卡牌效果,可以实现类似 Tinder、花田、明星空间等应用的喜欢、不喜欢 以及 关注功能,同时支持查看卡牌详细资料。

通过异步加载提高数据处理性能,并使用相同的布局参数作为框架布局(你可以在 xml 文件中使用 android:layout_gravity 定义布局样式)。

SwipeCardView

使用方法

首先,你需要导入模块项目或者添加依赖类库:

dependencies {
    compile 'online.osslab:SwipeCard:1.0.0'
}

核心用法:AdapterView

swipeCardView = (SwipeCardView) findViewById(R.id.swipeCardView);
//swipeCardView.setIsNeedSwipe(true); // 是否开启swipe滑动效果,当不调用此方法设置时,默认开启;
swipeCardView.setSwipeListener(this);
swipeCardView.setOnItemClickListener(this);

样式文件:XML

<online.osslab.SwipeCardView
        android:id="@+id/swipeCardView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        swipe:min_adapter_stack="4"
        swipe:max_visible="4"
        swipe:vertical_offset="28dp"/>

回调方法

  • onSwipeListener
    @Override
    public void removeFirstObjectInAdapter() {
        adapter.remove(0);
    }

    @Override
    public void onLeftCardExit(Object dataObject) {
        // 向左滑动
    }

    @Override
    public void onRightCardExit(Object dataObject) {
        // 向右滑动
    }

    @Override
    public void onAdapterAboutToEmpty(int itemsInAdapter) {
        if (itemsInAdapter == 3) {
            loadData();
        }
    }
  • OnItemClickListener
    @Override
    public void onItemClicked(MotionEvent event, View view, Object dataObject) {
        if (view.getTag() instanceof ViewHolder) {
            int x = (int) event.getRawX();
            int y = (int) event.getRawY();
            ViewHolder vh = (ViewHolder) view.getTag();
            View child = vh.portraitView;
            Rect outRect = new Rect();
            child.getGlobalVisibleRect(outRect);
            if (outRect.contains(x, y)) {
                // 查看详情
            } else {
                outRect.setEmpty();
                child = vh.collectView;
                child.getGlobalVisibleRect(outRect);
                if (outRect.contains(x, y)) {
                    // 关注明星
                }
            }
        }
    }

关于作者

许可协议

Copyright 2014 Dionysis Lorentzos

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.

About

卡牌效果:实现类似 Tinder 应用的喜欢、不喜欢 以及 关注功能,支持查看详细资料。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages