Android中怎么实现加载对话框效果-创新互联

Android中怎么实现加载对话框效果,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

创新互联是专业的莫力达网站建设公司,莫力达接单;提供成都网站设计、做网站、成都外贸网站建设公司,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行莫力达网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

第一种方式:使用动画让一个图片旋转


然后自定义Alertdialog,并对图片添加旋转动画:

public class LoadingDialog extends AlertDialog { private final String DEFAULT_TEXT="正在加载"; private ImageView mImageview; private TextView mTextView; private LinearLayout mLayout; private String mText; protected LoadingDialog(Context context) { super(context); // TODO Auto-generated constructor stub } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); mLayout=(LinearLayout) LinearLayout.inflate(getContext(), R.layout.loading_dialog, null); mImageview=(ImageView) mLayout.findViewById(R.id.loading_dialog_pic); mTextView=(TextView) mLayout.findViewById(R.id.loading_dialog_text); loadanimation(); getWindow().setContentView(mLayout); } private void loadanimation() {//对图片添加旋转动画 // TODO Auto-generated method stub Animation anim=AnimationUtils.loadAnimation(getContext(), R.anim.loading_dialog_anim); LinearInterpolator lin = new LinearInterpolator(); anim.setInterpolator(lin); mImageview.setAnimation(anim); }}

看一下xml的动画:

第二种方式:使用progressbar

首先是一个animation-list:

看一下布局的实现:

然后自定义一个alertdialog:

public class LoadingDialog extends AlertDialog { private final String DEFAULT_TEXT="正在加载"; private TextView mTextView; private LinearLayout mLayout; private String mText; protected LoadingDialog(Context context) { super(context); // TODO Auto-generated constructor stub } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); mLayout=(LinearLayout) LinearLayout.inflate(getContext(), R.layout.loading_dialog, null); mTextView=(TextView) mLayout.findViewById(R.id.loading_dialog_text); WindowManager m=(WindowManager) getContext().getSystemService(getContext().WINDOW_SERVICE); int windowwith=m.getDefaultDisplay().getWidth(); int w=windowwith*3/5; int h=300; getWindow().setLayout(w, h);//设置对话框窗体大小 getWindow().setContentView(mLayout); }}

关于Android中怎么实现加载对话框效果问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


分享标题:Android中怎么实现加载对话框效果-创新互联
网页链接:http://ybzwz.com/article/doochc.html