2015-06-10 195 views

回答

2

我曾经有过同样的问题,因为你,我无法找到一个图书馆刷卡显示其他的按钮,所以我最后写一个新的图书馆为我自己。看看我的图书馆:SwipeRevealLayout

为了您的具体布局,用法如下:

添加依赖关系:

compile 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.0.0' 

在你row.xml文件:

<com.chauthai.swipereveallayout.SwipeRevealLayout 
     android:layout_width="match_parent" 
     android:layout_height="70dp" 
     app:mode="normal" 
     app:dragEdge="right"> 

     <!-- Your delete and edit buttons layout here --> 
     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:orientation="horizontal"> 

      <!-- put your buttons here --> 

     </LinearLayout> 

     <!-- Your main layout here --> 
     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

</com.chauthai.swipereveallayout.SwipeRevealLayout> 

而且最后在你的适配器(RecyclerView或ListView)类中,当你绑定你的视图时,使用ViewBinderHelper:

public class Adapter extends RecyclerView.Adapter { 
    // This object helps you save/restore the open/close state of each view 
    private final ViewBinderHelper viewBinderHelper = new ViewBinderHelper(); 

    @Override 
    public void onBindViewHolder(ViewHolder holder, int position) { 
    // get your data object first. 
    YourDataObject dataObject = mDataSet.get(position); 

    // Save/restore the open/close state. 
    // You need to provide a String id which uniquely defines the data object. 
    viewBinderHelper.bind(holder.swipeRevealLayout, dataObject.getId()); 

    // do your regular binding stuff here 
    } 
} 
0

您需要将GestureListener添加到listview单元格的主布局中。对于这个看看这个: https://developer.android.com/training/gestures/detector.html

此外,您需要设置您的单元布局为RelativeLayout。这样做,你可以覆盖彼此之上的项目。接下来,您需要做的是将这些叠加项目的可见性设置为“开始”并听取用户的投掷手势。如果您检测到一个,请使覆盖项VISIBLE,以便用户可以选择它。

A.

相关问题