当我使用缩放动画触摸它时,我试图为EditText设置动画,我设法通过创建我自己的editText(扩展EditText)来实现。动画有效,但在此之后EditText大小(宽度)不会改变它仍然是一样的。我怎么能改变它?我试着打电话 动画后的this.setWidth(),但它不能很好地工作。哪个是解决我问题的最佳方法?
@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;
}