Android Build从右向左滑动ListView项以显示“删除"按钮(叠加在listview项上) [英] Android Build swipe ListView item from right to left show delete button (overlay on listview item)
问题描述
我要创建滑动列表视图,当用户在列表视图项上从右向左滑动时,将向用户显示一些按钮选项.
I want to create swipe listview, when user swipe right to left on an listview item, user will be show some button options.
它看起来像下面的图片:
It look like below image :
我已经看到一些滑动列表视图库,但这不是我所需要的.
I have been seen some swipe listview library, but it isn't what I need.
有人可以帮我建议可以建立我的列表视图的图书馆吗?
Can anyone help me suggest to me the library that can do build my listview?
谢谢.
推荐答案
我曾经遇到过与您相同的问题,我找不到可以滑动显示其他按钮的库,所以我最终为自己编写了一个新库.看看我的图书馆: SwipeRevealLayout
I used to have the same problem as your, I couldn't find a library to swipe to show other buttons so I ended up writing a new library for myself. Check out my library: SwipeRevealLayout
对于您的特定布局,用法如下:
For your specific layout, the usage is the following:
添加依赖项:
compile 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.0.0'
在row.xml文件中:
In your row.xml file:
<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:
And finally in your adapter (RecyclerView or ListView) class, when you bind your view, use 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
}
}
这篇关于Android Build从右向左滑动ListView项以显示“删除"按钮(叠加在listview项上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!