Android 加载对话框的实现
来源:互联网 发布:淘宝老a工具箱 编辑:程序博客网 时间:2024/05/16 02:19
这里简单说一下两种实现加载对话框的方式:1.使用动画让一个图片旋转 2.使用progressbar。
感觉简单来说,dialog就是一个弹出的window,把自己定义的布局放置到window里面就可以了,加载对话框就是有个加载的动画,核心的地方就是实现这个动画,所所以方法 可以有,对图片添加动画,或者使用progressbar。
第一种方式:使用动画让一个图片旋转
先看一下布局:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/dialog_bg_while" android:orientation="vertical" > <ImageView android:layout_width="54dp" android:id="@+id/loading_dialog_pic" android:layout_height="54dp" android:layout_gravity="center_horizontal" android:layout_marginTop="15dp" android:background="@drawable/loading" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="10dp" android:text="正在加载..." /></LinearLayout>
然后自定义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}@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.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 stubAnimation anim=AnimationUtils.loadAnimation(getContext(), R.anim.loading_dialog_anim);LinearInterpolator lin = new LinearInterpolator(); anim.setInterpolator(lin);mImageview.setAnimation(anim);}}
看一下xml的动画:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <rotate android:duration="1500" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0.0" android:repeatCount="infinite" android:toDegrees="-358" /></set>
第二种方式:使用progressbar
首先是一个animation-list:
<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/loading1" android:duration="100"/> <item android:drawable="@drawable/loading2" android:duration="100"/> <item android:drawable="@drawable/loading3" android:duration="100"/> <item android:drawable="@drawable/loading4" android:duration="100"/> <item android:drawable="@drawable/loading5" android:duration="100"/> <item android:drawable="@drawable/loading6" android:duration="100"/> <item android:drawable="@drawable/loading7" android:duration="100"/> <item android:drawable="@drawable/loading8" android:duration="100"/> </animation-list>
看一下布局的实现:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/dialog_bg_while" android:orientation="vertical" > <ProgressBar style="@android:style/Widget.ProgressBar.Large" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="10dp" android:indeterminateDrawable="@drawable/loading_animation_list" android:indeterminateDuration="1500" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#00BCD4" /> <TextView android:id="@+id/loading_dialog_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="10dp" android:text="正在加载..." /></LinearLayout>
然后自定义一个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}@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.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);}}
0 0
- Android 加载对话框的实现
- Android实现Zaker的加载对话框
- [转载]Android实现Zaker的加载对话框
- android 实现加载动画对话框
- Android对话框的实现
- android中自定义加载的对话框。。。。
- Android自定义对话框的实现
- Android之对话框的实现
- Android-对话框dialog的实现
- 自定义对话框的实现--Android
- Android自定义加载对话框
- Android中自定义的加载对话框和加载条
- Android中自定义的加载对话框和加载条
- ANDROID中自定义的加载对话框和加载条
- Android中自定义的加载对话框和加载条
- Android中自定义的加载对话框和加载条
- Android自定义控件-一行代码实现加载对话框
- 安卓简单的加载进度对话框实现
- 九度 1107 - 霍夫曼树 - 搬水果
- 结合Apache和Tomcat实现集群和负载均衡
- Doubles
- hdu 4333 Revolving Digits
- 解决COCOS2D-X与JNI交互游戏出现崩溃的问题call to OpenGL ES API with no current context (logged once per thread)
- Android 加载对话框的实现
- 《鸟哥的Linux私房菜-基础学习篇(第三版)》(六)
- 当你输入 nova boot时,client做了什么?
- Kinect v2.0原理介绍之五:只检测离kinect最近的人脸
- 数据结构学习笔记之线性结构--离散存储[链表]
- LocalBroadcastManager-让你的app广播更安全-源码解读
- 修改linux文件权限命令:chmod chgrp chown
- iOS中CocoaPods的安装和使用
- 二分图匹配