帮酷LOGO
  • 显示原文与译文双语对照的内容
堆叠滑动控件,类似于探探

  • 源代码名称:StackCardsView
  • 源代码网址:http://www.github.com/wensefu/StackCardsView
  • StackCardsView源代码文档
  • StackCardsView源代码下载
  • Git URL:
    git://www.github.com/wensefu/StackCardsView.git
  • Git Clone代码到本地:
    git clone http://www.github.com/wensefu/StackCardsView
  • Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/wensefu/StackCardsView
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
  • StackCardsView demo apk download

    堆叠滑动控件,类似于社交软件探探的效果,并增加以下扩展:

    • 支持滑动方向控制
    • 支持消失方向控制
    • 支持嵌入到ViewPager等滑动控件
    • 支持内嵌ListView,RecycleView等滑动控件

    效果演示

    演示1-快速滑动飞出     演示2-代码控制飞出

    演示3-嵌入到ViewPager     演示4-内嵌RecycleView

    如何使用

    • xml引入StackCardsView:
        <com.beyondsw.lib.widget.StackCardsView
            android:id="@+id/cards"android:layout_width="match_parent"android:layout_height="match_parent"app:itemHeight="340dp"app:itemWidth="340dp"android:paddingBottom="66dp"android:clipToPadding="false"        />

    支持的xml属性设置:

    属性名 说明 类型 是否必须
    itemWidth 卡片宽度 dimension
    itemHeight 卡片高度 dimension
    maxVisibleCnt 不滑动时最多可以看到的卡片数 integer
    edgeHeight 层叠效果高度 dimension
    scaleFactor 每层相对于上层的scale系数 float
    alphaFactor 每层相对于上层的alpha系数 float
    dismissFactor 滑动距离超过控件宽度的多少比例时消失 float
    dragSensitivity 滑动灵敏度 float



    设置adapter:  mCardsView =Utils.findViewById(root,R.id.cards);
      mCardsView.addOnCardSwipedListener(this);
      mAdapter =newCardAdapter();
      mCardsView.setAdapter(mAdapter);publicclassCardAdapterextendsStackCardsView.Adapter {
        privateList<BaseCardItem> mItems;
        publicvoidappendItems(List<BaseCardItem>items){
            int size = items ==null?0: items.size();
            if (size ==0) {
                return;
            }
            if (mItems ==null) {
                mItems =newArrayList<>(size);
            }
            mItems.addAll(items);
            notifyDataSetChanged();
        }
        publicvoidremove(intposition){
            mItems.remove(position);
            notifyItemRemoved(position);
        }
        @OverridepublicintgetCount() {
            return mItems ==null?0: mItems.size();
        }
        @OverridepublicViewgetView(intposition, ViewconvertView, ViewGroupparent) {
            return mItems.get(position).getView(convertView,parent);
        }
        @OverridepublicintgetSwipeDirection(intposition) {
            //这里控制每张卡的支持滑动超过一定距离消失的方向BaseCardItem item = mItems.get(position);
            return item.swipeDir;
        }
        @OverridepublicintgetDismissDirection(intposition) {
            //这里控制每张卡的支持滑动超过一定距离消失的方向BaseCardItem item = mItems.get(position);
            return item.dismissDir;
        }
        @OverridepublicbooleanisFastDismissAllowed(intposition) {
            //这里控制每张卡的支持快速滑动消失的方向BaseCardItem item = mItems.get(position);
            return item.fastDismissAllowed;
        }
        @OverridepublicintgetMaxRotation(intposition) {
             //这里控制每张卡的最大旋转角BaseCardItem item = mItems.get(position);
            return item.maxRotation;
        }
    }

    问题反馈

    License

    Copyright 2017 wensefu
    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.



    Copyright © 2011 HelpLib All rights reserved.    知识分享协议 京ICP备05059198号-3  |  如果智培  |  酷兔英语