开发者

Scale Animation on an EditText .. help

开发者 https://www.devze.com 2023-02-11 02:06 出处:网络
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 Ed

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;



}
0

精彩评论

暂无评论...
验证码 换一张
取 消