Imageview:图像更改动画

时间:2018-02-01 19:25:08

标签: android animation

我有这两张照片。请注意,在其中一个图像中,鸟眼被关闭。我想用这两个图像创建一个眨眼动画。 有没有可能使用imageswitcher或其他方式来做这个,而没有单独的眼睛图像和动画眼睛的高度变化?是这样,怎么样?

enter image description here enter image description here

2 个答案:

答案 0 :(得分:1)

你可以使用帧动画,使用这样的例子很简单。

res / drawable /文件夹中的

spin_animation.xml文件:

<animation-list android:id="@+id/selected" android:oneshot="false">
        <item android:drawable="@drawable/wheel0" android:duration="50" />
        <item android:drawable="@drawable/wheel1" android:duration="50" />
        <item android:drawable="@drawable/wheel2" android:duration="50" />
        <item android:drawable="@drawable/wheel3" android:duration="50" />
        <item android:drawable="@drawable/wheel4" android:duration="50" />
        <item android:drawable="@drawable/wheel5" android:duration="50" />
</animation-list>

以下是加载和播放此动画的代码。

     // Load the ImageView that will host the animation and
     // set its background to our AnimationDrawable XML resource.
     ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
     img.setBackgroundResource(R.drawable.spin_animation); 
    // Get the background, which has been compiled to an    AnimationDrawable object.
 AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();

 // Start the animation (looped playback by default).
 frameAnimation.start();

答案 1 :(得分:0)

您可以使用ViewFlipper

<强> XML

<ViewFlipper
        android:id="@+id/view_flipper"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/img1" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/img2" />
    </ViewFlipper>
活动

ViewFlipper mViewFlipper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mViewFlipper = findViewById(R.id.view_flipper);
        mViewFlipper.startFlipping();
        mViewFlipper.setFlipInterval(400);

    }

使用setFlipInterval()设置在图像之间滑动的时间(以毫秒为单位)

相关问题