简体   繁体   中英

How do I implement an animation of a picture hiding on top?

在此处输入图像描述

How to hide image on top using material animations? I can rotate image or change "X" "Y" but how can I do this task?

I guess you need to used clip. For example this file name is clipper.xml

 <?xml version="1.0" encoding="utf-8"?> <clip xmlns:android="http://schemas.android.com/apk/res/android" android:clipOrientation="vertical" android:drawable="@drawable/dog" android:gravity="bottom" />

Your image layout would contain this ImageView

 <androidx.appcompat.widget.AppCompatImageView android:id="@+id/imageView" android:layout_width="200dp" android:layout_height="200dp" android:src="@drawable/clipper" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />

And in you fragment you can use this snippet:

 val animator = ObjectAnimator.ofInt(0, 10000) animator.apply { interpolator = LinearInterpolator() duration = 1000 } animator.addUpdateListener { val animProgress = it.animatedValue as Int binding.imageView.drawable.level = 10000 - animProgress } animator.start()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM