当前位置:首页 > 谈天说地 > 正文内容

Android实现多张图片合成加载动画

34资源网2022年07月28日 11:01302

本文实例为大家分享了android实现多张图片合成加载动画的具体代码,供大家参考,具体内容如下

1、自定义progressdialog

public class myprogressdialog extends progressdialog {
    private int procressloadres;
    private imageview mimageview;
    private animationdrawable animationdrawable;

    public myprogressdialog(context context,int procressloadres) {
        super(context);
        this.procressloadres = procressloadres;
    }

    public myprogressdialog(context context, int theme, int procressloadres) {
        super(context, theme);
        this.procressloadres = procressloadres;
    }

    @override
    protected void oncreate(bundle savedinstancestate) {
        super.oncreate(savedinstancestate);
        setcontentview(r.layout.layout_progress);
        mimageview = (imageview) findviewbyid(r.id.image);
        //设置动画背景
        mimageview.setbackgroundresource(procressloadres);
        //获取动画对象,必须在上一步之后
        animationdrawable = (animationdrawable) mimageview.getbackground();
        mimageview.post(new runnable() {
            @override
            public void run() {
                //启动动画
                animationdrawable.start();
            }
        });
    }
}

2、myprogressdialog对应的布局layout_progress.xml

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="@null">

    <imageview
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</linearlayout>

3、使用自定义的myprogressdialog

public class mainactivity extends appcompatactivity {

    private button button;
    private myprogressdialog progressdialog;
    @override
    protected void oncreate(bundle savedinstancestate) {
        super.oncreate(savedinstancestate);
        setcontentview(r.layout.activity_main);
        button = (button) findviewbyid(r.id.button);
        //传入style和anim文件
        progressdialog = new myprogressdialog(this,r.style.dialog,r.anim.loading);

        button.setonclicklistener(new view.onclicklistener() {
            @override
            public void onclick(view view) {
                progressdialog.show();
            }
        });
    }
}

4、使用时需要一个style文件和一个anim文件

style.xml

<style name="dialog" parent="@android:style/theme.dialog">
        <!--边框-->
        <item name="android:windowframe">@null</item>
        <!--是否浮现在activity之上-->
        <item name="android:windowisfloating">true</item>
        <!--半透明-->
        <item name="android:windowistranslucent">false</item>
        <!--无标题-->
        <item name="android:windownotitle">true</item>
        <!--背景透明去掉背景色边框也就去掉了 -->
        <item name="android:windowbackground">@color/transparent</item> 
        <!--模糊-->
        <item name="android:backgrounddimenabled">false</item>
    </style>

anim文件夹下的loading.xml文件

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@mipmap/loading1" android:duration="100"/>
    <item android:drawable="@mipmap/loading2" android:duration="100"/>
    <item android:drawable="@mipmap/loading3" android:duration="100"/>
    <item android:drawable="@mipmap/loading4" android:duration="100"/>
    <item android:drawable="@mipmap/loading5" android:duration="100"/>
    <item android:drawable="@mipmap/loading6" android:duration="100"/>
    <item android:drawable="@mipmap/loading7" android:duration="100"/>
    <item android:drawable="@mipmap/loading8" android:duration="100"/>
    <item android:drawable="@mipmap/loading9" android:duration="100"/>
    <item android:drawable="@mipmap/loading10" android:duration="100"/>
    <item android:drawable="@mipmap/loading11" android:duration="100"/>
    <item android:drawable="@mipmap/loading12" android:duration="100"/>
    <item android:drawable="@mipmap/loading13" android:duration="100"/>
    <item android:drawable="@mipmap/loading14" android:duration="100"/>
    <item android:drawable="@mipmap/loading15" android:duration="100"/>
    <item android:drawable="@mipmap/loading16" android:duration="100"/>
    <item android:drawable="@mipmap/loading17" android:duration="100"/>
    <item android:drawable="@mipmap/loading18" android:duration="100"/>
    <item android:drawable="@mipmap/loading19" android:duration="100"/>
    <item android:drawable="@mipmap/loading20" android:duration="100"/>
    <item android:drawable="@mipmap/loading21" android:duration="100"/>
    <item android:drawable="@mipmap/loading22" android:duration="100"/>
    <item android:drawable="@mipmap/loading23" android:duration="100"/>
    <item android:drawable="@mipmap/loading24" android:duration="100"/>
    <item android:drawable="@mipmap/loading25" android:duration="100"/>
    <item android:drawable="@mipmap/loading26" android:duration="100"/>
    <item android:drawable="@mipmap/loading27" android:duration="100"/>
    <item android:drawable="@mipmap/loading30" android:duration="100"/>
    <item android:drawable="@mipmap/loading31" android:duration="100"/>
    <item android:drawable="@mipmap/loading32" android:duration="100"/>
    <item android:drawable="@mipmap/loading33" android:duration="100"/>
    <item android:drawable="@mipmap/loading34" android:duration="100"/>
</animation-list>

在color.xml文件中添加

<color name="transparent">#00ffffff</color>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持萬仟网。

看完文章,还可以用支付宝扫描下面的二维码领取一个支付宝红包,目前可领1-88元不等

支付宝红包二维码

除了扫码可以领取之外,大家还可以(复制 720087999 打开✔支付宝✔去搜索, h`o`n.g.包哪里来,动动手指就能领)。

看下图所示是好多参与这次活动领取红包的朋友:

支付宝红包

扫描二维码推送至手机访问。

版权声明:本文由34楼发布,如需转载请注明出处。

本文链接:https://www.34l.com/post/19941.html

分享给朋友:

相关文章

联合国秘书长:新冠疫苗必须要成为全球公共产品
联合国秘书长:新冠疫苗必须要成为全球公共产品

当地时间3月11日,联合国启动“必须团结一致”(Only Together)公共宣传活动,呼吁新冠疫苗能够在联合国疫苗计划主导下,成为全球公共产品,向全球各地有需要的人提供。联合国秘书长古特雷斯在致辞中表示,新冠肺炎疫情引发了全球巨大的苦难...

如何删掉分页符空白页(空白页的解决方法)
如何删掉分页符空白页(空白页的解决方法)

我相信大家在编辑Word文档时,一定都遇到过这种恼人的情况,好不容易编辑完文档了,却发现末尾留下了空白页,想删除都无从下手。那么到底如何快速删除Word空白页呢?今天就来教大家几招,保证让你删得干干净净! 方法一:Shift键删除空白...

ic卡与id卡区别(卡片类型和原理的区别)
ic卡与id卡区别(卡片类型和原理的区别)

IC卡全称为集成电路卡,也称智能卡,特点是可读写,可加密,安全性高、容量大,可存储数据,常用于一卡通系统;ID卡全称为身份识别卡,这只是一种感应卡,这种卡只可读不可写,有固定的编号,常用于门禁和考勤系统。 IC卡可以说是ID卡的一种升...

网站403怎么解决(网站403的解决办法)
网站403怎么解决(网站403的解决办法)

使用代理IP时经常会遇到各种问题,其中403错误并不少见。在上一篇《使用代理IP遇到403错误的可能原因有哪些》文中介绍了一些403错误的可能原因,今天我们一起来看看如何解决403错误,让工作可以正常进行。 一、代理服务器端返回的40...

诺基亚c2-01手机参数(诺基亚最新款手机)
诺基亚c2-01手机参数(诺基亚最新款手机)

诺基亚C2 Android Go Edition 价格:暂无价格 上市时间:2020年03月 屏幕尺寸:5.7英寸 分辨率:1520×720 触摸屏类型:电容触摸屏,多点触控CPU型号:紫光展锐SC9832E CPU核数:四核 操作系统...

冬奥场馆防疫合作方「布科思」,以消杀机器人布局空气环境领域
冬奥场馆防疫合作方「布科思」,以消杀机器人布局空气环境领域

2019年末,疫情正式着陆。几个月后,复旦大学张永振团队首次研究并公布了该病毒基因系列,此后,对于这次病毒的来源、传染途径以及基于各种宿主的争议达到了高潮。 对于这场疫情持续的时长,最开始人们和看待之前几乎每年春天都会爆发的传染病一样,以...