android - 如何在Android中制作线性显示动画而不是圆形显示动画?
问题描述
我想为我的按钮设置动画,该按钮从按钮的左侧偏移量显示到右侧。我想要的是线性显示动画而不是圆形显示动画。请帮我。谢谢。
更新
我想要两种基于线性显示动画显示和隐藏视图的方法。
解决方案
尝试下面的代码以获得线性显示效果 -
public class ViewAnimationUtils {
public static AnimatorSet createLinearReveal(final View viewToReveal, final int offsetWidth, final int offsetHeight, final int duration) {
viewToReveal.clearAnimation();
final int targetWidth = viewToReveal.getMeasuredWidth();
final int targetHeight = viewToReveal.getMeasuredHeight();
viewToReveal.getLayoutParams().height = offsetHeight;
viewToReveal.requestLayout();
final ValueAnimator heightAnimator = ValueAnimator
.ofInt(offsetHeight, targetHeight)
.setDuration(duration);
heightAnimator.addUpdateListener(animation -> {
viewToReveal.getLayoutParams().height = (int) animation.getAnimatedValue();
viewToReveal.requestLayout();
});
final ValueAnimator widthAnimator = ValueAnimator
.ofInt(offsetWidth, targetWidth)
.setDuration(duration);
widthAnimator.addUpdateListener(animation -> {
viewToReveal.getLayoutParams().width = (int) animation.getAnimatedValue();
viewToReveal.requestLayout();
});
final AnimatorSet set = new AnimatorSet();
set.playSequentially(widthAnimator, heightAnimator);
set.setInterpolator(new AccelerateInterpolator());
return set;
}
}
添加此类后,只需将您的视图传递给 createLinearReveal 方法的动画和偏移值。
推荐阅读
- javascript - 单击提交按钮后,如何将表单的状态设置为用户输入?
- swagger - 如何在另一个 API 中引用 Swaggerhub 上的 API?
- c# - 嵌入 PDF 内容的问题
- jquery - 使用 jQuery 1.12.4 在点击时将 V 形旋转 180 度
- python - 向数组的每个索引添加一个数字并创建一个新数组列表
- python - 使用 librosa python 的功率谱
- python - ns 分辨率的最大 numpy.datetime64 是多少
- python - 从 url 更新机器人的头像
- griddb - 如何在使用 GridDB 时识别同一行中列的新旧值
- powershell - PowerShell:将 HTML 表提取为 CSV