ChangeBounds Android 过渡
ChangeBounds Android Transition
我的应用程序中有一个回收视图,每一行都包含一个按钮,该按钮在按钮下方的同一单元格中显示文本。我使用 ChangeBounds 过渡使文本以平滑的动画显示,增加行高直到文本完全显示。所以当一个按钮被点击时,我会:
TransitionManager.beginDelayedTransition(row, transition)
holder.hiddenText.setVisibility(View.VISIBLE)
效果很好,但是有问题。正如预期的那样,隐藏的文本会出现一个增加其高度的动画。但是行高没有动画,从原来的高度一直跳到最终的高度,没有任何动画。
有什么方法可以在行上实现高度过渡,与文本同时增加?
在你的行布局上试试这个
public static void expand(final View v) {
v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
final int targetHeight = v.getMeasuredHeight();
// Older versions of android (pre API 21) cancel animations for views with a height of 0.
v.getLayoutParams().height = 1;
v.setVisibility(View.VISIBLE);
Animation a = new Animation()
{
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1
? LayoutParams.WRAP_CONTENT
: (int)(targetHeight * interpolatedTime);
v.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setDuration((int)(targetHeight / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);
}
行的线性或相对布局将动画化并展开。希望这能解决您的问题
如果你想让row
的动画也生效,那么你需要在row
的上一层执行beginDelayedTransition()
,在你的情况下可能是实际 RecyclerView
.
我的应用程序中有一个回收视图,每一行都包含一个按钮,该按钮在按钮下方的同一单元格中显示文本。我使用 ChangeBounds 过渡使文本以平滑的动画显示,增加行高直到文本完全显示。所以当一个按钮被点击时,我会:
TransitionManager.beginDelayedTransition(row, transition)
holder.hiddenText.setVisibility(View.VISIBLE)
效果很好,但是有问题。正如预期的那样,隐藏的文本会出现一个增加其高度的动画。但是行高没有动画,从原来的高度一直跳到最终的高度,没有任何动画。
有什么方法可以在行上实现高度过渡,与文本同时增加?
在你的行布局上试试这个
public static void expand(final View v) {
v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
final int targetHeight = v.getMeasuredHeight();
// Older versions of android (pre API 21) cancel animations for views with a height of 0.
v.getLayoutParams().height = 1;
v.setVisibility(View.VISIBLE);
Animation a = new Animation()
{
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1
? LayoutParams.WRAP_CONTENT
: (int)(targetHeight * interpolatedTime);
v.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setDuration((int)(targetHeight / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);
}
行的线性或相对布局将动画化并展开。希望这能解决您的问题
如果你想让row
的动画也生效,那么你需要在row
的上一层执行beginDelayedTransition()
,在你的情况下可能是实际 RecyclerView
.