Il ne semble pas y avoir un moyen facile de le faire via l'API, car l'animation modifie simplement la matrice de rendu de la vue, pas la taille réelle. Mais nous pouvons définir une marge négative pour tromper LinearLayout en pensant que la vue diminue.
Je vous recommande donc de créer votre propre classe Animation, basée sur ScaleAnimation, et de surcharger la méthode "applyTransformation" pour définir de nouvelles marges et mettre à jour la mise en page. Comme ça ...
public class Q2634073 extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.q2634073);
findViewById(R.id.item1).setOnClickListener(this);
}
@Override
public void onClick(View view) {
view.startAnimation(new MyScaler(1.0f, 1.0f, 1.0f, 0.0f, 500, view, true));
}
public class MyScaler extends ScaleAnimation {
private View mView;
private LayoutParams mLayoutParams;
private int mMarginBottomFromY, mMarginBottomToY;
private boolean mVanishAfter = false;
public MyScaler(float fromX, float toX, float fromY, float toY, int duration, View view,
boolean vanishAfter) {
super(fromX, toX, fromY, toY);
setDuration(duration);
mView = view;
mVanishAfter = vanishAfter;
mLayoutParams = (LayoutParams) view.getLayoutParams();
int height = mView.getHeight();
mMarginBottomFromY = (int) (height * fromY) + mLayoutParams.bottomMargin - height;
mMarginBottomToY = (int) (0 - ((height * toY) + mLayoutParams.bottomMargin)) - height;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
if (interpolatedTime < 1.0f) {
int newMarginBottom = mMarginBottomFromY
+ (int) ((mMarginBottomToY - mMarginBottomFromY) * interpolatedTime);
mLayoutParams.setMargins(mLayoutParams.leftMargin, mLayoutParams.topMargin,
mLayoutParams.rightMargin, newMarginBottom);
mView.getParent().requestLayout();
} else if (mVanishAfter) {
mView.setVisibility(View.GONE);
}
}
}
}
La mise en garde habituelle applique: parce que nous prépondérants une méthode protégée (applyTransformation), ce n'est pas garanti pour fonctionner dans les futures versions d'Android.
J'ai utilisé la même technique, comme Andy ici a présenté, sur mon ExpandAnimation: http://udinic.wordpress.com/2011/09/03/expanding-listview-items/ Je n'ai pas utilisé un animation d'échelle, je viens de construire une nouvelle classe d'animation pour cela. – Udinic
C'était très utile pendant que j'essayais de faire ça. Merci – atraudes
Excellent Udinic .. vraiment résolu mon problème .. :) merci –