Android开源堆叠滑动控件,类似探探

wensefu 8年前
   <h3>堆叠滑动控件,类似于社交软件探探的效果,并增加以下扩展:</h3>    <ul>     <li><strong>支持滑动方向控制</strong></li>     <li><strong>支持消失方向控制</strong></li>     <li><strong>支持嵌入到ViewPager等滑动控件</strong></li>     <li><strong>支持内嵌ListView,RecycleView等滑动控件</strong></li>    </ul>    <p> </p>    <p>效果演示</p>    <p><img alt="" src="https://simg.open-open.com/show/e41fd3856917304b7255da0e97a3901a.gif">         <img alt="" src="https://simg.open-open.com/show/1236bbc980f8e0f3e2c233e6d6462b2f.gif"></p>    <p> </p>    <p><img alt="" src="https://simg.open-open.com/show/4e97e1ef729f49794e9512dda06b35bb.gif">       <img alt="" src="https://simg.open-open.com/show/66efb641b7120bdb88cdc735c88063c0.gif"></p>    <p> </p>    <p> </p>    <h2>如何使用</h2>    <ul>     <li>xml引入StackCardsView:</li>    </ul>    <pre>  <code class="language-java">    <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"          /></code></pre>    <ul>     <li>支持的xml属性设置:</li>    </ul>    <table>     <thead>      <tr>       <th>属性名</th>       <th>说明</th>       <th>类型</th>       <th>是否必须</th>      </tr>     </thead>     <tbody>      <tr>       <td>itemWidth</td>       <td>卡片宽度</td>       <td>dimension</td>       <td>是</td>      </tr>      <tr>       <td>itemHeight</td>       <td>卡片高度</td>       <td>dimension</td>       <td>是</td>      </tr>      <tr>       <td>maxVisibleCnt</td>       <td>不滑动时最多可以看到的卡片数</td>       <td>integer</td>       <td>否</td>      </tr>      <tr>       <td>edgeHeight</td>       <td>层叠效果高度</td>       <td>dimension</td>       <td>否</td>      </tr>      <tr>       <td>scaleFactor</td>       <td>每层相对于上层的scale系数</td>       <td>float</td>       <td>否</td>      </tr>      <tr>       <td>alphaFactor</td>       <td>每层相对于上层的alpha系数</td>       <td>float</td>       <td>否</td>      </tr>      <tr>       <td>dismissFactor</td>       <td>滑动距离超过控件宽度的多少比例时消失</td>       <td>float</td>       <td>否</td>      </tr>      <tr>       <td>dragSensitivity</td>       <td>滑动灵敏度</td>       <td>float</td>       <td>否</td>      </tr>     </tbody>    </table>    <p><br>  </p>    <pre>  <code class="language-java">设置adapter:      mCardsView = Utils.findViewById(root,R.id.cards);    mCardsView.addOnCardSwipedListener(this);    mAdapter = new CardAdapter();    mCardsView.setAdapter(mAdapter);      public class CardAdapter extends StackCardsView.Adapter {        private List<BaseCardItem> mItems;        public void appendItems(List<BaseCardItem> items){          int size = items == null ? 0 : items.size();          if (size == 0) {              return;          }          if (mItems == null) {              mItems = new ArrayList<>(size);          }          mItems.addAll(items);          notifyDataSetChanged();      }        public void remove(int position){          mItems.remove(position);          notifyItemRemoved(position);      }        @Override      public int getCount() {          return mItems == null ? 0 : mItems.size();      }        @Override      public View getView(int position, View convertView, ViewGroup parent) {          return mItems.get(position).getView(convertView,parent);      }        @Override      public int getSwipeDirection(int position) {          //这里控制每张卡的支持滑动超过一定距离消失的方向          BaseCardItem item = mItems.get(position);          return item.swipeDir;      }        @Override      public int getDismissDirection(int position) {          //这里控制每张卡的支持滑动超过一定距离消失的方向          BaseCardItem item = mItems.get(position);          return item.dismissDir;      }        @Override      public boolean isFastDismissAllowed(int position) {          //这里控制每张卡的支持快速滑动消失的方向          BaseCardItem item = mItems.get(position);          return item.fastDismissAllowed;      }        @Override      public int getMaxRotation(int position) {           //这里控制每张卡的最大旋转角          BaseCardItem item = mItems.get(position);          return item.maxRotation;      }  }</code></pre>    <p> </p>