Android 自定义加载Dialog 运行效果流畅

如何实现Android 自定义加载Dialog,而且运行效果流畅。用ProgreBar效果不是很好。


下面介绍一种用ImageView+动画  实现。

1、在.xml中加入控件:

  <ImageView
        android:id="@+id/imgLoadingView"
        android:layout_width="40.0dip"
        android:layout_height="40.0dip"
        android:layout_margin="10.0dip"
        android:layout_gravity="center_vertical"
        android:background="@drawable/loading" />


2、自定义loading.xml:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false" >


    <item
        android:drawable="@drawable/loading_1"
        android:duration="100"/>
    <item
        android:drawable="@drawable/loading_2"
        android:duration="100"/>
    <item
        android:drawable="@drawable/loading_3"
        android:duration="100"/>
    <item
        android:drawable="@drawable/loading_4"
        android:duration="100"/>
    <item
        android:drawable="@drawable/loading_5"
        android:duration="100"/>
    <item
        android:drawable="@drawable/loading_6"
        android:duration="100"/>
    <item
        android:drawable="@drawable/loading_7"
        android:duration="100"/>
    <item
        android:drawable="@drawable/loading_8"
        android:duration="100"/>
    <item
        android:drawable="@drawable/loading_9"
        android:duration="100"/>
    <item
        android:drawable="@drawable/loading_10"
        android:duration="100"/>


</animation-list>

3、实现动画my_animation.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator" >
    <rotate
        android:duration="800"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="-1"
        android:repeatMode="restart"
        android:toDegrees="360" >
    </rotate>
</set>


4、在java中应用:

Animation anim = AnimationUtils.loadAnimation(context, R.anim.my_animation);
LinearInterpolator lir = new LinearInterpolator();
anim.setInterpolator(lir);
myView.setAnimation(anim);

很简单的一个例子。谢谢分享!!



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值