您的位置:首页 > 移动开发 > Android开发

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

2015-04-20 11:07 274 查看
如何实现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);

很简单的一个例子。谢谢分享!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android 自定义Dialog
相关文章推荐