我想创建滑动列表视图,当用户在列表视图项目上从右向左滑动时,用户将显示一些按钮选项。
如下图所示:
我看过一些刷卡列表视图库,但这不是我需要的。
任何人都可以帮我建议我可以建立我的列表视图的库吗?
感谢。
答案 0 :(得分:3)
我曾经遇到过和你一样的问题,我找不到要刷卡的图书库以显示其他按钮,所以我最终为自己编写了一个新的库。看看我的图书馆: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
}
}
答案 1 :(得分:0)
您需要将GestureListener添加到listview单元格的主布局中。为此,请看一下: https://developer.android.com/training/gestures/detector.html
此外,您还需要将单元格的布局设置为RelativeLayout。这样做,您可以将项目叠加在彼此之上。接下来,您需要做的是首先将这些叠加项的可见性设置为GONE,然后聆听用户甩动手势。如果您检测到一个,请使叠加项目可见,以便用户可以选择它。
一个。