zoukankan      html  css  js  c++  java
  • 自定义实现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;

     }

  • 相关阅读:
    Delphi公用函数单元
    Delphi XE5 for Android (十一)
    Delphi XE5 for Android (十)
    Delphi XE5 for Android (九)
    Delphi XE5 for Android (八)
    Delphi XE5 for Android (七)
    Delphi XE5 for Android (五)
    Delphi XE5 for Android (四)
    Delphi XE5 for Android (三)
    Delphi XE5 for Android (二)
  • 原文地址:https://www.cnblogs.com/arnoid/p/3042776.html
Copyright © 2011-2022 走看看