Android 动画布局更改了重量高度
Android animate layout changed weight height
我有两种布局
[layout 1]
[layout 2]
重量相等。当我向下滚动时,我更改 [layout 1]
和 [layout 2]
.
的权重
我想知道如何为布局更改权重设置动画。
我试过了
android:animateLayoutChanges="true"
和
LayoutTransition transition = new LayoutTransition();
mapLayout.setLayoutTransition(transition);`
但是 none 这个方法有效。
您可以执行与此调整大小动画类似的操作。
public class ResizeAnimation extends Animation
{
int _startWidth;
int _targetWidth;
View _view;
private int _targetHeight;
private int _startHeight;
public ResizeAnimation(View view, int targetWidth, int targetHeight)
{
_view = view;
_targetWidth = targetWidth;
_startWidth = view.getWidth();
_targetHeight = targetHeight;
_startHeight = view.getMeasuredHeight();
setFillAfter(true);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t)
{
int newWidth = (int) (_startWidth + (_targetWidth - _startWidth) * interpolatedTime);
int newHeight = (int) (_startHeight + (_targetHeight - _startHeight) * interpolatedTime);
_view.getLayoutParams().width = newWidth;
_view.getLayoutParams().height = newHeight;
_view.requestLayout();
}
@Override
public boolean willChangeBounds()
{
return true;
}
}
private class ExpandAnimation extends Animation {
private float mStartWeight;
private float mDeltaWeight;
private LinearLayout mContent;
private boolean direction;// true - up; false - down
public ExpandAnimation(LinearLayout content, float startWeight,
float endWeight) {
mStartWeight = startWeight;
mDeltaWeight = endWeight - startWeight;
mContent = content;
}
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContent
.getLayoutParams();
mStartWeight = lp.weight;
lp.weight = (mStartWeight + (mDeltaWeight * interpolatedTime));
mContent.setLayoutParams(lp);
}
@Override
public boolean willChangeBounds() {
return true;
}
}
我有两种布局
[layout 1]
[layout 2]
重量相等。当我向下滚动时,我更改 [layout 1]
和 [layout 2]
.
我想知道如何为布局更改权重设置动画。 我试过了
android:animateLayoutChanges="true"
和
LayoutTransition transition = new LayoutTransition();
mapLayout.setLayoutTransition(transition);`
但是 none 这个方法有效。
您可以执行与此调整大小动画类似的操作。
public class ResizeAnimation extends Animation
{
int _startWidth;
int _targetWidth;
View _view;
private int _targetHeight;
private int _startHeight;
public ResizeAnimation(View view, int targetWidth, int targetHeight)
{
_view = view;
_targetWidth = targetWidth;
_startWidth = view.getWidth();
_targetHeight = targetHeight;
_startHeight = view.getMeasuredHeight();
setFillAfter(true);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t)
{
int newWidth = (int) (_startWidth + (_targetWidth - _startWidth) * interpolatedTime);
int newHeight = (int) (_startHeight + (_targetHeight - _startHeight) * interpolatedTime);
_view.getLayoutParams().width = newWidth;
_view.getLayoutParams().height = newHeight;
_view.requestLayout();
}
@Override
public boolean willChangeBounds()
{
return true;
}
}
private class ExpandAnimation extends Animation {
private float mStartWeight;
private float mDeltaWeight;
private LinearLayout mContent;
private boolean direction;// true - up; false - down
public ExpandAnimation(LinearLayout content, float startWeight,
float endWeight) {
mStartWeight = startWeight;
mDeltaWeight = endWeight - startWeight;
mContent = content;
}
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContent
.getLayoutParams();
mStartWeight = lp.weight;
lp.weight = (mStartWeight + (mDeltaWeight * interpolatedTime));
mContent.setLayoutParams(lp);
}
@Override
public boolean willChangeBounds() {
return true;
}
}