首页 > 代码库 > 收藏提示动画效果
收藏提示动画效果
需求:点击收藏,屏幕中间弹出收藏提示动画,3秒后消失,且悬浮在app之上(即不会随着viewpager滑动和activity跳转而消失)
解决方案:
布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/layout" android:background="#00ffffff"> <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/tips_collection_success" /> </LinearLayout>
1.使用dialog
import android.app.Dialog; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.ImageView; import android.widget.LinearLayout; import com.xuehu365.xuehu.R; /** * Created by Administrator on 2016/12/27. */ public class CollectionAnimDialog { private Context context; private Dialog dialog; private View view; private LinearLayout layout; public CollectionAnimDialog(Context context) { this.context = context; } public CollectionAnimDialog builder() { view = LayoutInflater.from(context).inflate(R.layout.collection_anim_dialog, null); dialog = new Dialog(context, R.style.CollectionAnimDialogStyle); layout = (LinearLayout) view.findViewById(R.id.layout); layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); image = (ImageView) view.findViewById(R.id.image); dialog.setContentView(view); return this; } public void show() { dialog.show(); collectionAnim(); } /** * 收藏动画 */ private void collectionAnim() { AlphaAnimation alpha = new AlphaAnimation(1, 0); alpha.setDuration(3000); alpha.setFillAfter(true); alpha.setRepeatCount(0); layout.startAnimation(alpha); alpha.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { dialog.dismiss(); } @Override public void onAnimationRepeat(Animation animation) { } }); } }
dialog样式
<!-- CollectionAnimDialog收藏动画对话框样式 --> <style name="CollectionAnimDialogStyle" parent="@android:style/Theme.Dialog"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:windowFrame">@null</item> <item name="android:backgroundDimEnabled">false</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> </style>
2.Toast(推荐使用)
//收藏动画 Toast toast = new Toast(App.getApplication()); View view = LayoutInflater.from(App.getApplication()).inflate(R.layout.collection_anim_dialog, null); toast.setGravity(Gravity.CENTER, 0, 0); toast.setView(view); toast.show();
简单明了,动画系统自带,完美
收藏提示动画效果
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。