EditTextがあり、このxmlを使用して100%から80%にスケーリングしています。
<?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の幅を拡大縮小/変更するにはどうすればよいですか。よろしくお願いします。
私は答えを見つけました。ここにあります:
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);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加