2015-07-03 87 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"