Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale Item while Dragging #193

Closed
lkevin029 opened this issue Feb 21, 2016 · 9 comments
Closed

Scale Item while Dragging #193

lkevin029 opened this issue Feb 21, 2016 · 9 comments
Assignees
Milestone

Comments

@lkevin029
Copy link

How to make the item bigger when dragging start?
this is my code.

        mRecyclerViewDragDropManager.setOnItemDragEventListener(new RecyclerViewDragDropManager.OnItemDragEventListener() {
        @Override
        public void onItemDragStarted(int position) {
            View v = mRecyclerView.getChildAt(position);
            ScaleAnimation animation = new ScaleAnimation(1, 1.2f, 1, 1.2f, Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 1);
            v.setAlpha(0.5f);
            animation.setFillAfter(true);
            v.startAnimation(animation);

        }

        @Override
        public void onItemDragPositionChanged(int fromPosition, int toPosition) {

        }

        @Override
        public void onItemDragFinished(int fromPosition, int toPosition, boolean result) {
        }
    });

but its not working because the holder in dragging is different its just a copy of the original one.

I think its better you add holder in onItemDrag events so every one can make any changes in Item while dragging

@h6ah4i
Copy link
Owner

h6ah4i commented Feb 21, 2016

Hi. Thanks for your suggestion, but that is difficult to implement onItemDrag() like events.

  1. views and its holder objects will be recycled, so should not implement callback to holders
  2. in generally, item views should be manipulated in onBindViewHolder() method only
  3. dragging item is rendered as RecyclerView.ItemDecoration, so ObjectAnimator won't work

However, there is a way to implement scaling animation of the dragging item. You can achieve that by modifying the DraggingItemDecorator class of this library.

https://github.com/h6ah4i/android-advancedrecyclerview/blob/master/library/src/main/java/com/h6ah4i/android/widget/advrecyclerview/draggable/DraggingItemDecorator.java

@lkevin029
Copy link
Author

thank you for your reply this was helpful..
I got one more question
I got a gridlayout recyclerview
numbers = span

1 1 2 1 1

I can't drag the 2 in the corner its on purpose or it is a bug ?
lets just say 2 span width is bigger than 1 so i can't drag it in the 1st element of the row and last element...
sorry for my english >,<

@h6ah4i h6ah4i self-assigned this Feb 27, 2016
@h6ah4i h6ah4i added this to the next release milestone Feb 27, 2016
@h6ah4i
Copy link
Owner

h6ah4i commented Feb 27, 2016

@lkevin029 Thanks for pointing it out. I have just fixed the behavior for GridLayoutManager. Try the patched version of the library via jitpack.

build.gradle

repositories {
    maven { url "https://jitpack.io" }
}

dependencies {
    compile 'com.github.h6ah4i:android-advancedrecyclerview:fbb4f3bc883de883d79ec04d03d9cf74f2773322'
}

branch: https://github.com/h6ah4i/android-advancedrecyclerview/tree/feature/issue_193_improve_grid_layout_drag

@h6ah4i
Copy link
Owner

h6ah4i commented Mar 27, 2016

@lkevin029 The feature/issue_193_improve_grid_layout_drag branch has been merged into master branch now and released as v.0.8.7. Thanks.

@h6ah4i h6ah4i closed this as completed Mar 27, 2016
@richardjbs
Copy link

@h6ah4i I am trying to implement your suggestion to be able to scale the dragged view while dragging. I was trying to customize the DraggingItemDecorator. The issue is that the decorator is being use by the RecyclerViewDragDropManager internally on the startDragging() which is a private method. So extending from RecyclerViewDragDropManager to override startDragging and specify a custom DraggingItemDecorator is not an option. A lot of classes within the library are protected so I cannot use them on my project. I don't want to include all the source code on my project. I was trying to keep using gradle to import it dynamically. Any suggestion on this? How should I proceed to specify the DraggingItemDecorator implementation that I want to use to the RecyclerViewDragDropManager?

Thanks

@h6ah4i
Copy link
Owner

h6ah4i commented May 24, 2016

@richardjbs Hi. Yes, I meant that my suggestion require to fork this project. I admit that forking & modifying DraggingItemDecorator is not the best option. I think creating a new stable classes or API is needed, because DraggingItemDecorator is tightly integrated to RecyclerViewDragDropManager and it will be changed in future.

Also, I will reopen this issue. I closed this issue by mistake, I have fixed the sub-issue in v0.8.7 but the main issue is still not fixed yet.

Thanks

@h6ah4i h6ah4i reopened this May 24, 2016
@h6ah4i h6ah4i removed this from the 0.8.7 milestone May 24, 2016
h6ah4i added a commit that referenced this issue Aug 14, 2016
These methods are added to RecyclerViewDragDropManager;

- void setDraggingItemScale(float scale)
- float getDraggingItemScale()
- void setDraggingItemRotation(float rotation)
- float getDraggingItemRotation()
- void setDraggingItemAlpha(float alpha)
- float getDraggingItemAlpha()
- void setDragStartItemAnimationDuration(int duration)
- int getDragStartItemAnimationDuration()
- void setDragStartItemScaleAnimationInterpolator(Interpolator interpolator)
- void setDragStartItemRotationAnimationInterpolator(Interpolator interpolator)
- void setDragStartItemAlphaAnimationInterpolator(Interpolator interpolator)

Also, the `DraggableItemAnimator` is added. Using this ItemAnimator
gives better item animation if using drag and drop feature.
@h6ah4i h6ah4i added this to the next release milestone Aug 14, 2016
@h6ah4i
Copy link
Owner

h6ah4i commented Aug 14, 2016

Related #292.

@h6ah4i
Copy link
Owner

h6ah4i commented Oct 29, 2016

This enhancement has been included in v0.10.0.

@h6ah4i h6ah4i closed this as completed Oct 29, 2016
@egek92
Copy link

egek92 commented May 25, 2018

setDraggingItemScale(float scale) works perfect but it only draws inside the recyclerView bounds, is it possible to make it get bigger on outside as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants