daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

Inflate swipe layout opened (dragged) #341

Open vladut-lp opened 8 years ago

vladut-lp commented 8 years ago

Hi,

I am trying to inflate all my list items opened (dragged to left), but I don't really know how. On the xml there is no property to set for the view to be created like that. I have also tried to call open(false, false) or simple open() on method "onBindViewHolder" of my RecyclerViewAdapter, but with no success. I suppose when I call it, the item is not yet inflated.

Any ideas ?

Thanks, Vladut

Buckstabue commented 8 years ago

Hello. I've faced with the very similar problem. I need to restore the expand state of SwipeLayout when screen is rotated. I would like to hear any ideas

vladut-lp commented 8 years ago

Hi,

I have found a newbie workaround... but it is not what I'm looking for. At the end of my "onBindViewHolder" method on recycleradapter, I have added a handler to delay the open action. What I really want, is to show the user that he can swipe left the list items. So I want that when the items are inflated, the layout to be opened, and after 1 second to close them. Here is my first try to achieve that :

try { final Handler handlerOpen = new Handler(); handlerOpen.postDelayed(new Runnable() { @Override public void run() { itemSwipe.open(false, false); } }, 100);

            final Handler handlerClose = new Handler();
            handlerClose.postDelayed(new Runnable() 
              {
                @Override
                public void run() {
                    itemSwipe.close();
               }
            }, 1000);

} catch (Exception e) { Log.e("RecycleAdapter", "On bind view error: " + e.getMessage()); }

It seems to work... but I'm pretty sure it's far from the best method to do what I want.

I have another idea where I would change the SwipeLayout class (add a method) where I set a boolean (animateAtFirst), true, and a int/float animationTime to specify how long should the layout stay "opened". On SwipeLayout , somewhere (I'm not really sure where, on view initialization, maybe after is inflated) I should check this property and if it's true, on the view initialization I should change the main and back layout positions, and also start a handler (waiting animation time I set on the new method) to "close" the swipeLayout.

Does that makes sense ?

Thanks ! Ps : Sorry for the code's look.... insert code function is useless, or I don't know how to use it.

jd-alexander commented 7 years ago

a better approach is to do this. This ensures the layout is opened once the SwipeLayout is initialized.

swipeLayout.post(new Runnable() {
            @Override
            public void run() {
                swipeLayout.open();
            }});