问题
In my project I've setted the background color of my items (composed of several elements inserted in a ConstraintLayout) inside a ListView but the default animation of click and long click disappears if the background color is not at least a little transparent. In fact, as transparency decreases, the effect of clicking on the elements is less and less evident. In a few words, color goes to hide the animation if isn't transparent. How to solve this problem and then bring selection animation to the foreground?
Same problem, still unresolved: ListView items not showing tap animation
回答1:
RESOLVED!
You have to simply add android:drawSelectorOnTop="true"
in your ListView XML tag. In this way you can modify and customize the list item background and at the same time bring back the "selector" on top of the "z axis" of GUI. Yuhu!
回答2:
If you are giving a background coloraturas to the list items then you might be hiding the system press animations. in this case you can use the methods like OnItemLongClickListener() and itemClickListener () and add your custom animations to the view.
来源:https://stackoverflow.com/questions/58399672/android-studio-listview-onclick-animation-doesnt-work-if-you-set-background-co