Skip to content

一个带渐变层叠动画的左右滑动效果(类似于探探左右刷脸)

License

Notifications You must be signed in to change notification settings

UncleNine/SwipeCardView

 
 

Repository files navigation

SwipeCardView

SwipeCard效果是基于Diolor的Swipecards控件改进实现,通过添加了滑动渐变层叠动画,达到更佳的滑动刷脸体验。
thanks Diolor Swipecards

Screenshot

效果图

Usage

XML配置:

<com.lorentzos.flingswipe.SwipeFlingAdapterView
        android:id="@+id/swipe_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        swipe:min_adapter_stack="4"
        swipe:max_visible="4"
        swipe:y_offset_step="28dp"/>

Java Code:

核心用法(即AdapterView的用法)

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

onFlingListener的回调方法

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

    @Override
    public void onLeftCardExit(Object dataObject) {
        AppToast.show(this, "swipe left card");
    }

    @Override
    public void onRightCardExit(Object dataObject) {
        AppToast.show(this, "swipe right card");
    }

    @Override
    public void onAdapterAboutToEmpty(int itemsInAdapter) {
        if (itemsInAdapter == 3) {
            loadData();
        }
    }

OnItemClickListener的回调方法

    @Override
    public void onItemClicked(MotionEvent event, View v, Object dataObject) {
        if (v.getTag() instanceof ViewHolder) {
            int x = (int) event.getRawX();
            int y = (int) event.getRawY();
            ViewHolder vh = (ViewHolder) v.getTag();
            View child = vh.portraitView;
            Rect outRect = new Rect();
            child.getGlobalVisibleRect(outRect);
            if (outRect.contains(x, y)) {
                AppToast.show(this, "click 大图");
            } else {
                outRect.setEmpty();
                child = vh.collectView;
                child.getGlobalVisibleRect(outRect);
                if (outRect.contains(x, y)) {
                    AppToast.show(this, "click 关注");
                }
            }
        }
    }

也可参考Swipecards,两者用法基本一致。

About me

微博:@萧雾宇
Gmail:[email protected]

About

一个带渐变层叠动画的左右滑动效果(类似于探探左右刷脸)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%