自定义实现ProgressDialog样式的Dialog
1.? 建立一個my_progress_dialog.xml布局文件
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" ??? android:layout_width="200dip" ??? android:layout_height="200dip" >
??? <ImageView ????
??? android:id="@+id/iv_progressDialog"
??????? android:layout_width="wrap_content" ?
?????? android:layout_height="wrap_content" ??
????? android:layout_centerInParent="true" ?
?????? android:src="@drawable/my_progress_dialog_rotate" />
??? <TextView ?
?????? android:id="@+id/tv_progressDialog" ??
????? android:layout_width="wrap_content" ?
?????? android:layout_height="wrap_content" ???
???? android:layout_below="@id/iv_progressDialog" ??
????? android:layout_centerHorizontal="true" ??
????? android:layout_marginTop="10dip" ??
????? android:gravity="center" ?????
??? android:text="load..." />
</RelativeLayout>
?
2.在res目錄下建立文件anim/my_progress_dialog_rotate_anim.xml,自定義動畫
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" ??? android:shareInterpolator="false" >
??? <!-- 定義一個MyProgressDialog中imageView轉動的動畫 -->
??? <rotate ??????? android:duration="1500" ?
????????? ?? android:fromDegrees="0" ????
???????? ?? android:interpolator="@android:anim/linear_interpolator" ??
??????????? android:pivotX="50%" ???
?????????? android:pivotY="50%" ????
????????? android:repeatCount="-1" ?
???????? android:repeatMode="restart" ????
?????? ?android:startOffset="-1" ???
?????? ?android:toDegrees="+360" />
</set>
?
3.在values的styles.xml中添加Dialog樣式
?<!-- 自定義loading dialog -->
??? <style name="myProgressDialog" parent="android:style/Theme.Dialog">
??????? <item name="android:windowFrame">@null</item>
??????? <item name="android:windowNoTitle">true</item>
??????? <item name="android:windowBackground">@android:color/white</item>
??????? <item name="android:windowIsFloating">true</item>
??????? <item name="android:windowContentOverlay">@null</item>
??? </style>
?
4.自定義一個方法實現Dialog
/** ? * 得到自定義的progressDialog
? * ? * @param context ?
* @param msg ?
* @return ?
*/
?public static Dialog createLoadingDialog(Context context, String msg) {
??LayoutInflater inflater = LayoutInflater.from(context);
??View v = inflater.inflate(R.layout.my_progress_dialog, null);// 得到加載view
??ImageView spaceshipImage = (ImageView) v.findViewById(R.id.iv_progressDialog);
??TextView tipTextView = (TextView) v.findViewById(R.id.tv_progressDialog);// 提示文字 ?
?// 加載動畫 ?
?Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(context, R.anim.my_progress_dialog_rotate_anim); ??// 使用ImageView顯示動畫 ??spaceshipImage.startAnimation(hyperspaceJumpAnimation);
??tipTextView.setText(msg);// 設置加載信息
??Dialog loadingDialog = new Dialog(context, R.style.myProgressDialog);// 創建自定義樣式dialog
??loadingDialog.setCancelable(false);
??loadingDialog .setContentView(v, new LinearLayout.LayoutParams(150, 150)); ?
?return loadingDialog;
?}
?
?
轉載于:https://www.cnblogs.com/arnoid/archive/2013/04/25/3042776.html
總結
以上是生活随笔為你收集整理的自定义实现ProgressDialog样式的Dialog的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C# 通过拼音检索中文名称
- 下一篇: 分分钟手写http server