Swipe Layoutフレームはサイドラ削除編集機能を実現します。


本論文の例では、SwipeLayoutを共有し、編集者の具体的なコードを削除することを実現しました。参考にしてください。具体的な内容は以下の通りです。
ステップ1、依存を追加

dependencies {
  compile 'com.android.support:recyclerview-v7:21.0.0'
  compile 'com.android.support:support-v4:20.+'
  compile "com.daimajia.swipelayout:library:1.2.0@aar"
}
第二ステップ、レイアウトファイル

//      BottomView    layout_gravity  ,         
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="80dp">
<!-- Bottom View Start-->
 <LinearLayout
  android:background="#66ddff00"
  android:id="@+id/bottom_wrapper"
  android:layout_width="160dp"
  android:weightSum="1"
  android:layout_height="match_parent">
  <!--What you want to show-->
  <!--                -->
  <!-     TextView  Button--->
</LinearLayout>
<!-- Bottom View End-->

<!-- Surface View Start -->
 <LinearLayout
  android:padding="10dp"
  android:background="#ffffff"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <!--What you want to show in SurfaceView-->
  <!--               -->
</LinearLayout>
<!-- Surface View End -->
</com.daimajia.swipe.SwipeLayout>

ステップ3で、ActivityでSwipeLayoutの例を取得します。

SwipeLayout swipeLayout = (SwipeLayout) view.findViewById(R.id.swipelayout);
  //       
  swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
  //         layout_gravity  ,      
  //swipeLayout.addDrag(SwipeLayout.DragEdge.Left, findViewById(R.id.bottom_wrapper));
これで一つの目的の横滑り機能が実現されます。
私たちがListviewでこの機能を使うなら、BaseSwipeAdapterを引き継ぎ、中のいくつかの方法を複写する必要があります。

//  swipeLayout  
 @Override
public int getSwipeLayoutResourceId(int position) {
  return R.id.swipelayout;
}

//      ,   BaseAdapter   getView()  
@Override
public View generateView(int position, ViewGroup parent) {
  View view = LayoutInflater.from(mContext).inflate(R.layout.listview_item, null);
  SwipeLayout swipeLayout = (SwipeLayout) view.findViewById(R.id.swipelayout);
  //               
  swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);    
  return view;
}
//          
@Override
public void fillValues(int position, View convertView) {

}
//        BaseAdapter     ,BaseSwipeAdapter     BaseAdapter
@Override
public int getCount() {
  return 0;
}

@Override
public Object getItem(int i) {
  return null;
}

@Override
public long getItemId(int i) {
  return 0;
}
これにより、ListViewのエントリの横滑りがほぼ実現されます。削除/編集のコードをクリックして、メソッドgenerate View()で実現します。以下はListviewに項目を追加してイベントをクリックします。

//   swipeLayout generateView()            
swipeLayout.getSurfaceView().setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

    }
});
もし横滑りの時に他のロジックを実現する必要があるなら、横滑りのモニターを追加してもいいです。

swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
 @Override
 public void onClose(SwipeLayout layout) {
  //when the SurfaceView totally cover the BottomView.
 }

 @Override
 public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
  //you are swiping.
 }

 @Override
 public void onStartOpen(SwipeLayout layout) {

 }

 @Override
 public void onOpen(SwipeLayout layout) {
  //when the BottomView totally show.
 }

 @Override
 public void onStartClose(SwipeLayout layout) {

 }

 @Override
 public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
  //when user's hand released.
 }
});
ここで、ListView横滑り機能はほぼ実現されます。
以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。