1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| @Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
super.onKeyDown(keyCode, event);
View MainMenu = findViewById(R.id.menu_principal);
ArrayList<View> Buttons = MainMenu.getTouchables();
Animation setZoomIn = AnimationUtils.loadAnimation(ctx,
R.anim.menuzoomin);
Animation setZoomOut = AnimationUtils.loadAnimation(ctx,
R.anim.menuzoomout);
switch (keyCode)
{
case KeyEvent.KEYCODE_DPAD_LEFT:
{
for (View view : Buttons)
{
applyAnimation(view, setZoomIn);
}
return true;
}
case KeyEvent.KEYCODE_DPAD_RIGHT:
{
}
}
return (true);
}
private void applyAnimation(final View view, final Animation anim)
{
anim.setAnimationListener(new Animation.AnimationListener()
{
private boolean doEnd = true;
@Override
public void onAnimationEnd(Animation animation)
{
if (doEnd)
{
doEnd = false;
setViewPos(view, anim, anim.getStartTime() + anim.getDuration());
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
});
view.startAnimation(anim);
}
private void setViewPos(View view, Animation anim, long time)
{
// Get the transformation
Transformation trans = new Transformation();
anim.getTransformation(time, trans);
// Get the matrix values
float[] values = new float[9];
Matrix m = trans.getMatrix();
m.getValues(values);
// Get the position and apply the scroll
/*final float x = values[Matrix.MTRANS_X];
final float y = values[Matrix.MTRANS_Y];
view.scrollTo(-(int)x, -(int)y);*/
final float width = values[Matrix.MSCALE_X];
final float height = values[Matrix.MSCALE_Y];
final ImageButton test = (ImageButton) view;
android.view.ViewGroup.LayoutParams params = test.getLayoutParams();
params.height =10;//(int) (height * view.getLayoutParams().height) ;
params.width =10;//(int) (width * view.getLayoutParams().width);
test.setLayoutParams(params);
//setWidth((int) (width * view.getLayoutParams().width));
//Button.setHeight((int) (height * view.getLayoutParams().height));
//view.getLayoutParams().height = (int) (height * view.getLayoutParams().height);
//view.getLayoutParams().width = (int) (width * view.getLayoutParams().width);
//view.setScaleX(width);
//view.setScaleY(height);
} |
Partager