Reputation: 333
I have an EditText and I am scaling it from 100% to 80% with this xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
android:duration="400"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="0%"
android:pivotY="0%"
android:toXScale="0.8"
android:toYScale="1.0" >
</scale>
</set>
After this my text in it is scaled too. How can I scale/change EditText width with animation without scaling the text in it. Regards to all.
Upvotes: 3
Views: 1479
Reputation: 12300
You can try doing this in your layout:
android:animateLayoutChanges="true"
Upvotes: 0
Reputation: 333
I have found an answer. Here it is:
public class ResizeWidthAnimation extends Animation
{
private int mWidth;
private int mStartWidth;
private View mView;
public ResizeWidthAnimation(View view, int width)
{
mView = view;
mWidth = width;
mStartWidth = view.getWidth();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t)
{
int newWidth = mStartWidth + (int) ((mWidth - mStartWidth) * interpolatedTime);
mView.getLayoutParams().width = newWidth;
mView.requestLayout();
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight)
{
super.initialize(width, height, parentWidth, parentHeight);
}
@Override
public boolean willChangeBounds()
{
return true;
}
}
And calling it like this:
ResizeWidthAnimation anim = new ResizeWidthAnimation(editTextSearch, 500);
anim.setDuration(400);
editTextSearch.startAnimation(anim);
Upvotes: 4