自己定义progressdialog载入动画,这里还有旋转的载入条,美团,多个图片动画
2023-09-11 14:20:59 时间
自己定义progressdialog载入动画,这里还有旋转的载入条,美团,多个图片动画
下载Demo:http://download.csdn.net/detail/menglele1314/8775497
public class MainActivity extends Activity { private Button submit; private AnimationDrawable fightnimation, fightnimationab; private ImageView pb, net, netab; private Dialog mLoading; private Animation animation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); submit = (Button) findViewById(R.id.btn_login_submit); pb = (ImageView) findViewById(R.id.iv_failure); animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.cirle); animation.setInterpolator(new LinearInterpolator()); netab = (ImageView) findViewById(R.id.iv_netab); netab.setBackgroundResource(R.anim.fight); fightnimationab = (AnimationDrawable) netab.getBackground(); net = (ImageView) findViewById(R.id.iv_net); net.setBackgroundResource(R.anim.loading); fightnimation = (AnimationDrawable) net.getBackground(); submit.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mLoading = createLoadingDialog(MainActivity.this); mLoading.show(); // mLoading.dismiss(); pb.startAnimation(animation); fightnimationab.start(); fightnimation.start(); } }); }
/** * 得到自己定义的progressDialog * * @param context * @return */ public static Dialog createLoadingDialog(Context context) { LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(R.layout.layout_loading_dialog, null); // 得到载入view LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view); // 载入布局 ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img); Animation animation = AnimationUtils.loadAnimation( context, R.anim.cirle); // 载入动画 animation.setInterpolator(new LinearInterpolator()); spaceshipImage.startAnimation(animation); // 使用ImageView显示动画 Dialog loadingDialog = new Dialog(context, R.style.loading_dialog); // 创建自己定义样式dialog // loadingDialog.setCancelable(false);// 不能够用"返回键"取消 loadingDialog.setContentView(layout, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); return loadingDialog; } }
下载Demo:点击打开链接
相关文章
- CSS动画基础知识
- 动画详解常用排序算法(1)
- iOS核心动画 - CALayer
- 【Harmony OS】【JAVA UI】webView 动画加载资源加载动画交互
- SwiftUI 动画特效之代码雨组建电影特性(项目含源码)
- SwiftUI 绘图之绘制自定义形状并动画展示(对勾图形含代码)
- requestAnimationFrame,Web中写动画的另一种选择
- 给不定高度/宽度元素添加CSS3 transition动画
- vue 使用动画钩子函数
- 【历史上的今天】3 月 29 日:“机器人三定律”问世;电脑动画首次获得奥斯卡;Caldera Linux 沉浮史
- 设置安卓开机动画、开机logo
- iOS - Core Animation(核心动画)