2015-07-03 84 views
2

我有一个EditText,我从100%与该XML缩放它以80%:使用缩放动画更改EditText宽度,而不缩放其中的字符?

<?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> 

这是我在它的文字太缩放后。 如何缩放/更改带有动画的EditText宽度,而不缩放文本。关心所有。

回答

3

我找到了答案。那就是:

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; 
} 
} 

并调用它像这样:

ResizeWidthAnimation anim = new ResizeWidthAnimation(editTextSearch, 500); 
    anim.setDuration(400); 
    editTextSearch.startAnimation(anim); 
0

您可以尝试在你的布局这样做:

android:animateLayoutChanges="true"