Giter Club home page Giter Club logo

swipemenu's Introduction

SwipeMenu

A swipe menu for horizontal/vertical, support left/right and top/bottom directions, low coupling, can fast rapid integration into your project

Features

  • Support LinearLayoutManager、GridLayoutManager and StaggeredGridLayoutManager for RecyclerView (only horizontal)
  • Support ListView and GridView (only horizontal)
  • Support ScrollView (only horizontal and the [SwipeHorizontal/SwipeVertical]MenuLayout must be the direct child of ScrollView's direct child )
  • On-off swipe ability
  • Not intercept item touch event
  • Left/Right and Top/Bottom menu support, free switch

Preview

DEMO

Usage

Add to dependencies

dependencies {
    compile 'com.tubb.smrv:swipemenu-recyclerview:5.4.8'
}

Horizontal

Just use SwipeHorizontalMenuLayout, we use SwipeHorizontalMenuLayout ViewGroup to combine item content view and left/right(at least one) swipe menu

<?xml version="1.0" encoding="utf-8"?>
<com.tubb.smrv.SwipeHorizontalMenuLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:sml="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sml"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    sml:sml_scroller_interpolator="@android:anim/bounce_interpolator"
    sml:sml_auto_open_percent="0.2"
    sml:sml_scroller_duration="250">

    <include android:id="@id/smContentView" layout="@layout/item_simple_content"/>
    <include android:id="@id/smMenuViewLeft" layout="@layout/item_simple_left_menu"/>
    <include android:id="@id/smMenuViewRight" layout="@layout/item_simple_right_menu"/>

</com.tubb.smrv.SwipeHorizontalMenuLayout>

If you have so many items, you may be want to use our custom RecyclerView

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}"
    android:id="@+id/swipeRefreshLayout">

    <com.tubb.smrv.SwipeMenuRecyclerView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.v4.widget.SwipeRefreshLayout>

Vertical

Just use SwipeVerticalMenuLayout, we use SwipeVerticalMenuLayout ViewGroup to combine item content view and top/bottom (at least one) swipe menu

<com.tubb.smrv.SwipeVerticalMenuLayout
    android:id="@+id/sml"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    sml:sml_scroller_interpolator="@android:anim/bounce_interpolator">

    <LinearLayout
        android:id="@id/smMenuViewTop"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:orientation="horizontal"
        android:clickable="true"
        android:background="@android:color/holo_green_light"
        android:gravity="center_horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="top"
            android:textColor="@color/white"
            android:layout_gravity="top"/>

    </LinearLayout>

    <RelativeLayout
        android:id="@id/smContentView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/red">

        <Button
            android:id="@+id/btLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Top"
            android:layout_centerHorizontal="true"
            />

        <Button
            android:id="@+id/btRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Bottom"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"/>

    </RelativeLayout>

    <LinearLayout
        android:id="@id/smMenuViewBottom"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:orientation="horizontal"
        android:clickable="true"
        android:background="@android:color/holo_blue_light"
        android:gravity="center_horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="bottom"
            android:textColor="@color/white"
            android:layout_gravity="bottom"/>

    </LinearLayout>
</com.tubb.smrv.SwipeVerticalMenuLayout>

More details please see the demo project

Listeners

We add a SwipeSwitchListener for actions like open/close

sml.setSwipeListener(new SwipeSwitchListener() {
    @Override
    public void beginMenuClosed(SwipeMenuLayout swipeMenuLayout) {
        Log.e(TAG, "left menu closed");
    }

    @Override
    public void beginMenuOpened(SwipeMenuLayout swipeMenuLayout) {
        Log.e(TAG, "left menu opened");
    }

    @Override
    public void endMenuClosed(SwipeMenuLayout swipeMenuLayout) {
        Log.e(TAG, "right menu closed");
    }

    @Override
    public void endMenuOpened(SwipeMenuLayout swipeMenuLayout) {
        Log.e(TAG, "right menu opened");
    }
});

If you case a few actions, just use SimpleSwipeSwitchListener

sml.setSwipeListener(new SimpleSwipeSwitchListener(){
    @Override
    public void beginMenuClosed(SwipeMenuLayout swipeMenuLayout) {
        Log.e(TAG, "left menu closed");
    }
});

We also add a SwipeFractionListener for complete fraction action

sml.setSwipeFractionListener(new SwipeFractionListener() {
    @Override
    public void beginMenuSwipeFraction(SwipeMenuLayout swipeMenuLayout, float fraction) {
        Log.e(TAG, "top menu swipe fraction:"+fraction);

    }

    @Override
    public void endMenuSwipeFraction(SwipeMenuLayout swipeMenuLayout, float fraction) {
        Log.e(TAG, "bottom menu swipe fraction:"+fraction);
    }
});

If you case a few actions, just use SimpleSwipeFractionListener

sml.setSwipeFractionListener(new SimpleSwipeFractionListener(){
    @Override
    public void beginMenuSwipeFraction(SwipeMenuLayout swipeMenuLayout, float fraction) {
        Log.e(TAG, "top menu swipe fraction:"+fraction);
    }
});

Custom

Supported custom attrs:

  • sml_scroller_duration Scroller duration(ms), sml:sml_scroller_duration="250"
  • sml_auto_open_percent Swipe menu auto open percent(relative to menu's width), sml:sml_auto_open_percent="0.5"
  • sml_scroller_interpolator Scroller open/close interpolation, sml:sml_scroller_interpolator="@android:anim/bounce_interpolator"
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="SwipeMenu">
        <attr name="sml_scroller_duration" format="integer" />
        <attr name="sml_auto_open_percent" format="float"/>
        <attr name="sml_scroller_interpolator" format="reference"/>
    </declare-styleable>
</resources>

Thanks

Inspired by baoyongzhang/SwipeMenuListView

License

Copyright 2016 TUBB

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

swipemenu's People

Contributors

kozmi55 avatar lucasfoulonmongai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swipemenu's Issues

Menu item height match parent

How can I set menu item height = "match_parent" ?
Is it possible? Because in demo items have fixed height.
I have not fixed height items (with different height) and want placed menu item in center vertically of RV item

mCurrentSwiper become null

I'm using SwipeHorizontalMenuLayout on ExpandableListView.
And I'm defining a SwipeHorizontalMenuLayout in GroupView and ChildView of ExpandableListView.
But, Occur NullpointerException when click a SwipeMenu(left or right) in a ChildView.

mCurrentSwiper in follow code got null 😢

public class SwipeHorizontalMenuLayout extends SwipeMenuLayout {

...
     public void smoothCloseMenu(int duration) {
             mCurrentSwiper.autoCloseMenu(mScroller, getScrollX(), duration);
             invalidate();
     }
...

Is this bug? or Not supported for ExpandableListView??
Let me know why, and want to solve this problem.

Best regards m_ _m

smoothCloseMenu on RecyclerView closes the wrong list item

If i open the swipe menu on an item at the bottom of the recyclerview, on click i'm closing the menu. However an item, say 5 positions above that also suddenly appears open and closes immediately as well. Appears to be recycling of some sort but isn't the recyclerview supposed to handle this?

Menu over the content area

Is it possible to open right/left menu over the content area? I am using right menu and i don't want content area to be swiped when right menu is opened.

Basically i want smContentView and smMenuViewRight both to be shown when menu is opened, is it possible?

Not working inside viewpager

When i use swipeLayout inside 3 tab viewpager . it works by smoothOpen() / smoothClose() . BUT ONLY on 1st and 2nd slide. on last slide nothing works.

android:allowBackup="true" causes error with android gradle 0.11.1 when applications has android:allowBackup="false"

Error:Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : Attribute application@allowBackup value=(false) from AndroidManifest.xml:37:9-36
is also present at [com.tubb.smrv:swipemenu-recyclerview:2.0.1] AndroidManifest.xml:12:9-35 value=(true).
Suggestion: add 'tools:replace="android:allowBackup"' to element at AndroidManifest.xml:35:5-270:19 to override.

viewHolder.sml.smoothCloseMenu();这个方法有个问题,从后往前删没问题,如果从第一个开始删执行这个关闭方法就报下面BUG

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.tubb.smrv.b.d.b(android.widget.OverScroller, int, int)' on a null object reference
at com.tubb.smrv.SwipeHorizontalMenuLayout.b(SwipeHorizontalMenuLayout.java:275)
at com.tubb.smrv.SwipeMenuLayout.j(SwipeMenuLayout.java:108)
at com.android.lft.block.main.message.view.MessageCenterAdapter.a(MessageCenterAdapter.java:132)
at com.android.lft.block.main.message.view.MessageCenterListActivity.b(MessageCenterListActivity.java:220)
at com.android.lft.block.main.message.a.k.a(MessageStatusUpdatePresenterImpl.java:42)
at com.android.lft.block.common.a.l.a(ModelInterfaceImpl.java:145)
at com.android.lft.block.common.a.l.call(ModelInterfaceImpl.java:77)
at rx.ce.onNext(Observable.java:8192)
at rx.c.f.onNext(SafeSubscriber.java:139)
at rx.internal.operators.fa$a.call(OperatorObserveOn.java:207)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5438)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)

Use with fragment

Is it possible to use Recycleriew SwipeMenu with a fragment?
Thanx

页面显示问题

左边一个TextView,一行显示,超出一行用...结尾,右边可以滑出一个删除按钮;
问题描叙:当TextView的长度可以一行显示时,删除按钮可以正常滑出;一行显示不下时,删除按钮无法滑出。

Listeners??

Good re-work but You didnt forget about listeners for action like Open? Close ? for swiping items?

有个bug

在配合RecyclerView使用的时候,如果两根手指同时滑动不同的item,都会出现Menu,然后进行其他触摸后只会关闭掉其中一个,另外一个不会自动关闭,导致滑动后其他item出现错乱。希望作者能关注下
💯

SwipeHorizontalMenuLayout fractions cause crash in other languages

The line 204 below in SwipeHorizontalMenuLayout is crashing the library with a NumberFormatException when the language on the phone supports a decimal format with "," or other character (German for example).

fraction = Float.parseFloat(mDecimalFormat.format(fraction));

Fatal Exception: java.lang.NumberFormatException: Invalid float: ",14"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.initialParse(StringToReal.java:164)
at java.lang.StringToReal.parseFloat(StringToReal.java:323)
at java.lang.Float.parseFloat(Float.java:306)
at com.tubb.smrv.SwipeHorizontalMenuLayout.scrollTo(SwipeHorizontalMenuLayout.java:204)
at android.view.View.scrollBy(View.java:12526)
at com.tubb.smrv.SwipeHorizontalMenuLayout.onTouchEvent(SwipeHorizontalMenuLayout.java:102)
💯

Support both LEFT and RIGHT direction

Would you like to implement this? I think it could be more efficient to use:

SwipeMenuLayout.setSwipeDirection(DIRECTION_LEFT | DIRECTION_RIGHT);
SwipeMenuLayout.setLeftView();
SwipeMenuLayout.setRightView();

Please update for new gradle plugin 3.0.0

dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

一个bug

我自己已经修复了,就是垂直菜单只有buttom的时候 我调用openMenu方法而不是openButtonMenu 将导致空指针。

bug : android 2.3.4 NoSuchMethodError getMeasuredHeightAndState

java.lang.NoSuchMethodError: android.view.View.getMeasuredHeightAndState
at com.tubb.smrv.SwipeMenuLayout.onLayout(Unknown Source)

OVER_API_11 ? getMeasuredHeightAndState

if (mSwipeDirection == SwipeMenuRecyclerView.DIRECTION_LEFT) {
            mMenuView.layout(getMeasuredWidth(), tGap,
                    getMeasuredWidth() + (OVER_API_11 ? mMenuView.getMeasuredWidthAndState() : mMenuView.getMeasuredWidth()),
                    tGap + mMenuView.getMeasuredHeightAndState());
        } else {
            mMenuView.layout(-(OVER_API_11 ? mMenuView.getMeasuredWidthAndState() : mMenuView.getMeasuredWidth()), tGap,
                    0, tGap + mMenuView.getMeasuredHeightAndState());
        }

不兼容原生ripple effect

SDK21 下在列表item的布局中使用原生的

android:background="@drawble/my_ripple"

在点击时ripple effect, 效果不能正常消失
💯

发现了几个问题。

首先很感谢分享,项目做的真的不错。然后再使用过程中发现了几个问题,希望有时间可以考虑更新一下~~~

1、滑动打开删除时,不松开ITEM,引起的问题:

  1. 另一个手指再滑动任意的条目,可以打开第二条目,第三条目等,这时松开,点击其他条目,只关闭一个条目。
  2. 不松开会直接触发长按监听,是不是后面可以加入不触发长按监听了。(我目前的做法是调用setSwipeFractionListener当中的endMenuSwipeFraction监听,当fraction等于0的时候,才会触发长按监听。不过这个做法会引起一个问题,也是不松开的问题,就是说当触发长按弹出dialog以后,不松开,还是可以左右滑动。然后我加了一个holder.sml.setSwipeEnable(false); ,在MotionEvent.ACTION_UP:的时候,变成true,问题解决了,但是好麻烦。)。

2、往下随便滑动到某个位置,然后左滑打开一个删除,以下操作会引起删除的那行条目错位:

  1. 这时条目进行更新了。
  2. 跳转到其他页面,然后返回。

3、begin的一些监听没有调用到,close的调用到了。例如beginMenuClosed,beginMenuOpened,beginMenuSwipeFraction等,都没有调用到。

关于滑动出现菜单问题

为什么一定要给 SwipeMenuLayout设置一个setOnClickListener事件才能滑动出现菜单。不设置 SwipeMenuLayout的setOnClickListene事件怎么滑动都不能出现菜单?作者能解释下吗?

无法使用

Error:(105, 13) Failed to resolve: com.tubb.smrv:swipemenu-recyclerview:5.4.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.