Poi*_*n_X 2 android android-animation android-imageview
如何ImageView像FloatingActionButton下面的gif中的动画(显示和隐藏)那样为我设置动画。
您可以使用缩放动画来实现此目的。
scale_up.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="100"
android:fromXScale="0"
android:fromYScale="0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
Run Code Online (Sandbox Code Playgroud)
scale_down.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="100"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0"
android:toYScale="0" />
</set>
Run Code Online (Sandbox Code Playgroud)
并将动画应用到您的imageView上,您可以执行以下操作:
/**
* For scale up animation
*/
Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.scale_up);
child.startAnimation(animation);
child.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)
缩小比例
/**
* For scale down animation
*/
Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.scale_down);
child.startAnimation(animation);
child.setVisibility(View.INVISIBLE);
Run Code Online (Sandbox Code Playgroud)
这取决于您希望imageView放大和缩小的位置。