【问题标题】:Android animation of concentric expanding fading circles同心扩展渐变圆的Android动画
【发布时间】:2016-08-23 03:04:46
【问题描述】:

在 Android 中,我正在寻找尽可能简单的“内置”方式来创建可绘制的视图或自定义视图,以动画化 4 个半径缓慢扩大的同心圆。

从哪里开始最好?
是否可以在纯 XML 中执行此操作?
如果没有,可以使用单层可绘制对象来完成,还是应该使用多层可绘制对象?

谢谢!

【问题讨论】:

  • 尝试浏览安卓阿森纳。那将是您寻找此类物品的最佳首选地点。
  • 尝试搜索 Animated Drawables。
  • @swooby 我也在尝试做这样的事情,但只使用单层可绘制,虽然我不知道你是如何为你的可绘制 xml 中的每个项目列表设置动画的,我问了一个问题,但还没有回答.请帮忙
  • @SameerKhan1406 抱歉,我还没有找到答案……还没有……
  • @swooby 这应该会有所帮助,github.com/skyfishjy/android-ripple-background

标签: android android-layout android-animation android-drawable


【解决方案1】:

最好的起点是this repository。这是Android 的一个易于配置的波纹背景动画。插上电源,你就可以开始了。步骤如下:

要在安装后进行设置,像这样将RippleBackground 添加到您的布局中,

<com.skyfishjy.library.RippleBackground
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/content"
    app:rb_color="#0099CC"
    app:rb_radius="32dp"
    app:rb_rippleAmount="4"
    app:rb_duration="3000"
    app:rb_scale="6">
    <ImageView
        android:layout_width="64dp"
        android:layout_height="64dp"
        android:layout_centerInParent="true"
        android:id="@+id/centerImage"
        android:src="@drawable/demoImage"/>
</com.skyfishjy.library.RippleBackground>

然后就可以像这样重写onClick方法来启动动画了,

final RippleBackground rippleBackground=(RippleBackground)findViewById(R.id.content);
ImageView imageView=(ImageView)findViewById(R.id.centerImage);
imageView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        rippleBackground.startRippleAnimation();
    }
});

调用rippleBackground.stopRippleAnimation()方法停止动画。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-29
    相关资源
    最近更新 更多