ZacDomingue 4年前
   <h2>介绍</h2>    <p>CardSwipeLayout - Use RecyclerView to achieve card swipe layout , like <a href="/misc/goto?guid=4959740329326028726" rel="nofollow,noindex">Tantan</a> .</p>    <h2>效果</h2>    <p><img src=""></p>    <h2>使用</h2>    <h3>step 1</h3>    <p>For build.gradle :</p>    <pre>  <code class="language-java">compile 'me.yuqirong:cardswipelayout:1.0.0'</code></pre>    <p>Or Maven :</p>    <pre>  <code class="language-java"><dependency>    <groupId>me.yuqirong</groupId>    <artifactId>cardswipelayout</artifactId>    <version>1.0.0</version>    <type>pom</type>  </dependency></code></pre>    <h3>step 2</h3>    <p>init RecyclerView firstly :</p>    <pre>  <code class="language-java">RecyclerView recyclerView = (RecyclerView) findViewById(;  recyclerView.setAdapter(...);</code></pre>    <h3>step 3</h3>    <p>then set CardLayoutManager for RecyclerView and CardItemTouchHelperCallback for ItemTouchHelper . In addition , don't forget set OnSwipeListener for CardItemTouchHelperCallback :</p>    <pre>  <code class="language-java">// dataList means dataSource for adapter  CardItemTouchHelperCallback cardCallback = new CardItemTouchHelperCallback(recyclerView.getAdapter(), dataList);  ItemTouchHelper touchHelper = new ItemTouchHelper(cardCallback); CardLayoutManager cardLayoutManager = new CardLayoutManager(recyclerView, touchHelper);  recyclerView.setLayoutManager(cardLayoutManager);  touchHelper.attachToRecyclerView(recyclerView);  cardCallback.setOnSwipedListener(new OnSwipeListener<T>() {        @Override      public void onSwiping(RecyclerView.ViewHolder viewHolder, float ratio, int direction) {          /**           * will callback when the card are swiping by user           * viewHolder : thee viewHolder of swiping card           * ratio : the ratio of swiping , you can add some animation by the ratio           * direction : CardConfig.SWIPING_LEFT means swiping from left;CardConfig.SWIPING_RIGHT means swiping from right           *             CardConfig.SWIPING_NONE means not left nor right           */      }        @Override      public void onSwiped(RecyclerView.ViewHolder viewHolder, T t, int direction) {          /**           *  will callback when the card swiped from screen by user           *  you can also clean animation from the itemview of viewHolder in this method           *  viewHolder : the viewHolder of swiped cards           *  t : the data of swiped cards from dataList           *  direction : CardConfig.SWIPED_LEFT means swiped from left;CardConfig.SWIPED_RIGHT means swiped from right           */      }        @Override      public void onSwipedClear() {          /**           *  will callback when all cards swiped clear           *  you can load more data            */      }    });</code></pre>    <p>Finally , enjoy it !!!</p>    <p>If you have any questions , you can leave a message in <a href="/misc/goto?guid=4959740329421094822" rel="nofollow,noindex">Issues</a> .</p>    <h2>联系我</h2>    <ul>     <li>Email : <a href="/misc/goto?guid=4959740329505482905" rel="nofollow,noindex"></a></li>     <li>Weibo :@活得好像一条狗</li>    </ul>    <h2>许可</h2>    <pre>  <code class="language-java">MIT License    Copyright (c) 2017 yuqirong    Permission is hereby granted, free of charge, to any person obtaining a copy  of this software and associated documentation files (the "Software"), to deal  in the Software without restriction, including without limitation the rights  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  copies of the Software, and to permit persons to whom the Software is  furnished to do so, subject to the following conditions:    The above copyright notice and this permission notice shall be included in all  copies or substantial portions of the Software.    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  SOFTWARE.</code></pre>    <p> </p>    <p> </p>