Scale Animation on an EditText .. help
i'm trying to animate an EditText when i touch it using scale animation , i managed to do that by creating my own editText (extends Ed开发者_高级运维itText) .The animation works , but after it the EditText size(width) does not change it still the same . How can i change that ? I tried to call this.setWidth() after the animation , but it does not work so well. Which is the best approach for my problem ?
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
focus = true;
this.setText("");
this.setTextColor(Color.parseColor("#000000"));
if (firstTime) {
animate();
}
break;
case MotionEvent.ACTION_UP:
text = this.getText().toString();
break;
}
return super.onTouchEvent(event);
}
private void animate() {
Log.i("teste", "ed width: " + this.getWidth());
Log.i("teste", "parent width: " + parent.getWidth());
float x = ((float) parent.getWidth() / this.getWidth());
Log.i("teste", "x: " + x);
ScaleAnimation sc = new ScaleAnimation(1, x, 1, 1, 0.5f, 0.0f);
sc.setStartOffset(100);
sc.setInterpolator(new AccelerateInterpolator());
sc.setFillAfter(true);
sc.setDuration(1000);
this.startAnimation(sc);
invalidate();
firstTime = false;
}
精彩评论