AVE*_*imi 5 animation android android-4.4-kitkat
如何使用ViewPropertyAnimator设置视图宽度?
我可以缩放或翻译(见下文),但我不能设置为特定的宽度.
frame_1.animate().scaleX(5).scaleY(5).start();
Run Code Online (Sandbox Code Playgroud)
但没有
frame_1.animate().width(1024).height(768).start();
Run Code Online (Sandbox Code Playgroud)
小智 1
使用简单的动画代替 ViewPropertyAnimator
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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1196 次 |
| 最近记录: |