`
ontheway_lyl
  • 浏览: 44703 次
社区版块
存档分类
最新评论

android基于dialog加载时转圈圈的demo

阅读更多
最近公司需要android开发,缺人,我就被活生生的拉了过来,还好之前有java基础,搞起来虽然费力,但要比纯新手好一些。在过程中有很多东西很多功能,都是参考网上很多大牛和雷锋的blog,省去了很多弯路,对于今天我要发的android基于dialog加载loading时转圈圈的demo,其实我网上也搜过,都没找到全套的,和合适的,有个全套的,csdn的分很高没下到,于是我决定自己研究,在此分享出来,希望对有需要的同学有所帮助。废话不多说,直接上代码:
本blog系本人原创,转载或使用时请注明出处
1、主activity:
public class MainActivity extends Activity {

	@Override
	protected 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);
	            }
	        });

	}

	@Override
	public 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、实现加载旋转的dialog
public 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
  • 大小: 8.7 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics