Do TV side for a while, I saw another TV on a touch pad through the remote control of a picture of the corresponding direction of the jitter, feel the novelty of listening to, try to do a share:
Reprint Annotated Source: http://www.cnblogs.com/hyylog/p/5666806.html
In fact, it is very simple to control by rotating animation:
Directly on the code:
public class Imagesew extends ImageView {
private int state = 0;//0 Normal 1 Tilt 2 under Tilt 3 do tilt 4 right tilt
private int degress;
Private Valueanimator Startanimator;
Private Valueanimator Endanimator;
Public Imagesew (context context, AttributeSet Attrs) {
Super (context, attrs);
}
@Override
protected void OnDraw (canvas canvas) {
Super.ondraw (canvas);
}
public void initeanimation (int member, int duration) {
degress = member;
Startanimator = Valueanimator.ofint (0,member);
Endanimator = Valueanimator.ofint (0,member);
Startanimator.setduration (duration);
Endanimator.setduration (duration);
Startanimator.addlistener (New Animatorlistener () {
@Override
public void Onanimationstart (Animator animation) {
}
@Override
public void Onanimationrepeat (Animator animation) {
}
@Override
public void Onanimationend (Animator animation) {
Endanimator.start ();
Endanimator.addlistener (New Animatorlistener () {
@Override
public void Onanimationstart (Animator animation) {
}
@Override
public void Onanimationrepeat (Animator animation) {
}
@Override
public void Onanimationend (Animator animation) {
Setrotationx (0);
Setrotationx (0);
}
@Override
public void Onanimationcancel (Animator animation) {
}
});
}
@Override
public void Onanimationcancel (Animator animation) {
}
});
Startanimator.addupdatelistener (New Animatorupdatelistener () {
@Override
public void Onanimationupdate (Valueanimator animation) {
int value = (Integer) animation.getanimatedvalue ();
if (state==1)
Setrotationx (value);
else if (state==2)
Setrotationx (0-value);
else if (state = = 3)
Setrotationy (0-value);
else if (state = = 4)
Setrotationy (value);
}
});
Endanimator.addupdatelistener (New Animatorupdatelistener () {
@Override
public void Onanimationupdate (Valueanimator animation) {
int value = (Integer) animation.getanimatedvalue ();
if (state==1)
Setrotationx (Degress-value);
else if (state==2)
Setrotationx (value-degress);
else if (state = = 3)
Setrotationy (value-degress);
else if (state = = 4)
Setrotationy (Degress-value);
}
});
}
@Override
protected void Dispatchdraw (canvas canvas) {
Super.dispatchdraw (canvas);
}
public void Upbitmap () {
state = 1;
Start ();
}
public void Downbitmap () {
state = 2;
Start ();
}
public void Leftbitmap () {
state = 3;
Start ();
}
public void Rightbitmap () {
state = 4;
Start ();
}
public void Start () {
Cancelanimation ();
Startanimator.start ();
}
public void Cancelanimation () {
Startanimator.cancel ();
Endanimator.cancel ();
Setrotationx (0);
Setrotationy (0);
}
}
TV-side: Through the remote control to achieve the image of the upper and lower left and right jitter effect