最近公司需要android开发,缺人,我就被活生生的拉了过来,还好之前有java基础,搞起来虽然费力,但要比纯新手好一些。在过程中有很多东西很多功能,都是参考网上很多大牛和雷锋的blog,省去了很多弯路,对于今天我要发的android基于dialog加载loading时转圈圈的demo,其实我网上也搜过,都没找到全套的,和合适的,有个全套的,csdn的分很高没下到,于是我决定自己研究,在此分享出来,希望对有需要的同学有所帮助。废话不多说,直接上代码:
本blog系本人原创,转载或使用时请注明出处1、主activity:public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button btn = (Button)findViewById(R.id.progressButtom);        btn.setOnClickListener(new OnClickListener()        {           public void onClick(View v)            {                //多个Activity嵌套时用this.parent否则异常                new ProgersssDialog(MainActivity.this);            }        });}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}2、实现加载旋转的dialogpublic class ProgersssDialog extends Dialog {    private ImageView img;    private TextView txt;            public ProgersssDialog(Context context) {            super(context, R.style.progress_dialog);                  //加载布局文件           LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);            View  view=inflater.inflate(R.layout.progress_dialog, null);             img=(ImageView) view.findViewById(R.id.progress_dialog_img);            txt=(TextView) view.findViewById(R.id.progress_dialog_txt);            //给图片添加动态效果           Animation anim=AnimationUtils.loadAnimation(context, R.anim.loading_dialog_progressbar);            img.setAnimation(anim);            txt.setText(R.string.progressbar_dialog_txt);            //dialog添加视图           setContentView(view);           show();  //显示//           dismiss(); //取消显示    }    public void setMsg(String msg){            txt.setText(msg);    }    }3、动画anim文件loading_dialog_progressbar.xml<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:shareInterpolator="false" ><rotate         android:interpolator="@android:anim/linear_interpolator"        android:pivotX="50%"        android:pivotY="50%"        android:fromDegrees="0"        android:toDegrees="+360"        android:duration="1000"        android:startOffset="-1"        android:repeatMode="restart"        android:repeatCount="-1"/></set>4、dialog上加载旋转的layout:progress_dialog.xml<?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:orientation="vertical"     android:gravity="center">        <RelativeLayout         android:id="@+id/home_loading_layout"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        >    <ImageView         android:id="@+id/progress_dialog_img"        android:layout_width="60dp"        android:layout_height="60dp"       android:layout_marginLeft="30dp"        android:src="@drawable/loading"/>        <TextView         android:id="@+id/progress_dialog_txt"        android:layout_below="@id/progress_dialog_img"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/progressbar_dialog_txt"/>    </RelativeLayout>    </LinearLayout>

附件上有真实的效果图,本blog系本人原创,转载或使用时请注明出处

也何以直接去下载demo文件,资源图片什么都有 http://download.csdn.net/detail/ontheway_lyl/7424227

更多相关文章

  1. 在Android中通过jni方式使用编译好的FFmpeg库-Android中使用FFmp
  2. Android下使用JDOM访问XML文件
  3. Android(安卓)引用外部项目库
  4. 一次偶然机遇找到一个不错的关于Android实现加载gif动画的实例,写
  5. [Android(安卓)之美] 那些你不知道的APK 瘦身,让你的APK更小
  6. android/NDK开发assets资源中文名打包问题
  7. g1安装android软件详细攻略
  8. android重用layout-include标签的使用
  9. 如何访问android的asset目录和res目录下的文件

随机推荐

  1. Android(安卓)RecyclerView DividerItemD
  2. android - TextView单行显示...或者文字
  3. ch010 Android(安卓)GridView
  4. android内存机制
  5. Android(安卓)核心分析 之八------Androi
  6. [Android官方API阅读]___
  7. 周记:Class4
  8. Android: Android(安卓)3.0 SDK发布,速度
  9. Android之SharedPreferences用法
  10. SQLite 锁机制与事务简介