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

最近公司需要android开发,缺人,我就被活生生的拉了过来,还好之前有java基础,搞起来虽然费力,但要比纯新手好一些。在过程中有很多东西很多功能,都是参考网上很多大牛和雷锋的blog,省去了很多弯路,对于今天我要发的android基于dialog加载loading时转圈圈的demo,其实我网上也搜过,都没找到全套的,和合适的,有个全套的,csdn的分很高没下到,于是我决定自己研究,在此分享出来,希望对有需要的同学有所帮助。废话不多说,直接上代码:
[/code]
本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
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值