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

Elevation is not applied correctly with getActivationElevation #761

Open
dzielins42 opened this issue May 7, 2020 · 1 comment
Open

Comments

@dzielins42
Copy link

Hello, I came up with an issue. I've tried to implement simple list with draggable items. Dragged item has to have elevation (shadow). I've tried to use getActivationElevation but it does not work as described in wiki.

According to Wiki, getActivationElevation returns value of desired elevation when view is activated (eg. dragged), however this value is not applied correctly.

I've done some investigation myself. FlexibleViewHolder.toggleActivation correctly calls ViewCompat.setElevation with value from getActivationElevation. However, this is quickly overwritten by ItemTouchUIUtilImpl.onDraw. The new elevation value is 1f + findMaxElevation(...), and findMaxElevation ignores dragged item. This means that, if my base items have no elevation, dragged item will have elevation 1f no matter what value is returned by getActivationElevation.

This is easily reproducible in demo app, just change value returned in Simple.getActivationElevation to see that it has no effect or remove elevation from root RelativeLayout in recycler_header_item.xml to see that it will change elevation of item to 1f.

@dzielins42
Copy link
Author

There is a rather hacky way to walk around it.
Implementing getActivationElevation as below will trick ItemTouchUIUtilImpl.

@Override
public float getActivationElevation() {
   itemView.setTag(R.id.item_touch_helper_previous_elevation,50f);
   return (Float)itemView.getTag(R.id.item_touch_helper_previous_elevation);
}

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

No branches or pull requests

1 participant