Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android同心圆缩放动画_Android_Android Layout_Animation_Android Animation - Fatal编程技术网

Android同心圆缩放动画

Android同心圆缩放动画,android,android-layout,animation,android-animation,Android,Android Layout,Animation,Android Animation,我正在尝试创建一个动画,其中两个同心圆上下缩放(轴位于其中心) 如果我将动画设置为两个圆中的任意一个,它将在其中心正确缩放,但如果我将动画设置为两个圆,则轴是错误的 以下是一个屏幕截图: 这是我的布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="

我正在尝试创建一个动画,其中两个同心圆上下缩放(轴位于其中心)

如果我将动画设置为两个圆中的任意一个,它将在其中心正确缩放,但如果我将动画设置为两个圆,则轴是错误的

以下是一个屏幕截图:

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <RelativeLayout
        android:id="@+id/soundCircle"
        android:layout_width="230dp"
        android:layout_height="230dp"
        android:layout_gravity="center">

        <View
            android:id="@+id/soundRipple2"
            android:layout_width="230dp"
            android:layout_height="230dp"
            android:background="@drawable/circle"
            android:alpha="0.08"
            android:layout_centerInParent="true"/>
        <View
            android:id="@+id/soundRipple3"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:background="@drawable/circle"
            android:alpha="0.08"
            android:layout_centerInParent="true"/>

    </RelativeLayout>
</LinearLayout>

这是动画:

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:toXScale="0.7"
    android:toYScale="0.7" 
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatMode="reverse"
    android:fillAfter="true"
    android:repeatCount="infinite"/>

这可能是由同一动画的两个实例共享的轴点造成的。在我玩了一段时间之后,我发现如果将动画的不同实例指定给
视图
s,那么这种方法是有效的

这是我使用的代码:

Animation pulse = AnimationUtils.loadAnimation(this, R.anim.pulse);
Animation pulse2 = AnimationUtils.loadAnimation(this, R.anim.pulse);

circle1.startAnimation(pulse);
circle2.startAnimation(pulse2);

我已经尝试过这个动画和动画作品很好。在浏览一些网站和git存储库之后。我找到了一个最好的解决办法,也许它也会对你有所帮助。不需要为该动画添加多个视图。只要访问一次,我相信你也喜欢这种效果。

谢谢,这确实是课程的共享实例。复制动画XML不是必需的,只需要一个,我已编辑了我的答案。谢谢,今天就到此为止!那个图书馆就是我最后使用的。