I am making an android app, and I have a button which leads to a messaging place. On the activity with the button, I check if there is any unread messages, and if so I want to do something to the button to let the user know that there is something unread.
I was thinking of having the button sorta vibrate horizontally like 3 shakes every 2 or 3 seconds.
I know how to run a thread in the background which does something every x milliseconds. But what I don't know what to do is shake it horizontally 3 times.
Can anyone help with this?
I was thinking of using the sin function, for the animation, I can use output from a sin function to get values that go up and down, which I can set the horizontal position of the button... But this seems too extreme, is there a better way?
Thanks.
Dependency
Add it in your root build.gradle at the end of repositories:
and then add dependency
dependencies { compile 'com.github.varunest:sparkbutton:1.0.5' }
Usage
XML
Java (Optional)
create shake.xml in anim folder
and cycle.xml in anim folder
now add animation on your code
If you want vertical animation, change fromXdelta and toXdelta value to fromYdelta and toYdelta value
Class.Java
For onClick of the Button
Create the anim folder in res directory
Right click on, res -> New -> Directory
Name the new Directory anim
create a new xml file name it milkshake
milkshake.xml
I can't comment on @omega's comment because I don't have enough reputation but the answer to that question should be something like:
shake.xml
Class.java
This is just one way of doing what you want, there may be better methods out there.
uss to: