• Stars
    star
    2,385
  • Rank 19,281 (Top 0.4 %)
  • Language
    Java
  • Created almost 9 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

enable users to slide card to the left or right smoothly and continuously

有图有真相

模仿探探首页的卡片滑动效果:

preview 不得不说,探探的ui效果真的很赞。在着手这个project之前,我没有参考过github上其它类似的开源项目。所以,如果这个project重复造了轮子,请不要打我。

在这个仓库竣工之时,有一个小伙伴发了我另一个开源工程,颇有相似之处。我下载了源码,导入了studio,apk跑起来的时候,发现它存在一些问题:卡片飞到两侧,如果动画没有结束,则不允许下一轮拖动。这对强迫症的用户来说,应该是很不爽的。

然而,探探却克服了所有这些问题。或许,这个问题只有积淀过这些知识点的人才能琢磨的透吧。我确实思考了很久,想到了一个还不错的方案。

无耻一点

如果我能不要脸一些,我会说这个项目有以下优点:

  • 快。真的流畅,滑动的手速再快也赶不上代码刷新view的速度快。
  • 高效。仅仅四个卡片view轻松搞定任意多的数据。
  • 灵活。自定义ViewGroup对卡片view的高度实现了自适应。
  • 细节。卡片之间联动的视觉效果,是像素级的精确。

不信,你下载下来look look。

使用方法

1. 在xml文件中引入CardSlidePanel

<com.stone.card.library.CardSlidePanel
        android:id="@+id/image_slide_panel"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        card:bottomMarginTop="38dp"
        card:itemMarginTop="10dp"
        card:yOffsetStep="13dp" />

2. 左右滑动监听

cardSwitchListener = new CardSlidePanel.CardSwitchListener() {

        @Override
        public void onShow(int index) {
            Log.d("Card", "正在显示-" + dataList.get(index).userName);
        }

        @Override
        public void onCardVanish(int index, int type) {
            Log.d("Card", "正在消失-" + dataList.get(index).userName + " 消失type=" + type);
        }
};
slidePanel.setCardSwitchListener(cardSwitchListener);

3. 绑定Adapter

slidePanel.setAdapter(new CardAdapter() {
        @Override
        public int getLayoutId() {
            // layout文件
            return R.layout.card_item;
        }

        @Override
        public int getCount() {
            // 卡片个数
            return dataList.size();
        }
        
        @Override
        public Rect obtainDraggableArea(View view) {
            // 可滑动区域定制,仅调用一次
            return new Rect(....)
        }

        @Override
        public void bindView(View view, int index) {
            // 数据绑定,参看demo
            viewHolder.bindData(dataList.get(index));
        }
});

4. 数据更新

// appendDataList
adapter.notifyDataSetChanged();

Demo安装包

apk download (就在thisProj工程之中)

License

Copyright 2016, xmuSistone

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.

More Repositories

1

ViewpagerTransition

viewpager with parallax pages, together with vertical sliding (or click) and activity transition
Java
3,039
star
2

AndroidPileLayout

An abnormal horizontal ListView-like pile layout with stretch and contraction effects.
Java
2,157
star
3

VegaLayoutManager

√A customized LayoutManager - fade and shrink the head itemView when scrolling.
Java
1,859
star
4

VerticalSlideFragment

vertical slide to switch to the next fragment page, looks like vertical viewpager
Java
1,606
star
5

DragRankSquare

edit personal information which enables users to drag and rank image order
Java
1,118
star
6

AnimRichEditor

rich text editor which enables users to insert/delete bitmaps and text into edit-view with animations.
Java
976
star
7

android-snake-menu

imitate Tumblr's menu, dragging animations look like a snake
Java
584
star
8

stickyViewpager

[deprecated] sticky view in viewpager which includes scrollview and listview - viewpager with headers
Java
313
star
9

PersistentRecyclerView

京东首页 - 长列表内嵌ViewPager商品流(RecyclerView方案)
Kotlin
308
star
10

PersistentCoordinatorLayout

京东首页 - 长列表内嵌ViewPager商品流(CoordinatorLayout方案)
Kotlin
212
star
11

android-character-animation

in textview, characters come along one by one with random alpha animation
Java
59
star
12

android-slide-to-unlock

imitate ios, slide to unlock, text color gradient animation
Java
47
star
13

AutoWrapLayout

a customized viewgroup wraps textviews and aligns on both left and right sides.
Java
46
star
14

boringArticles

just some articles
19
star
15

MailExtension

chrome插件 - 工资条助手
JavaScript
14
star