当前位置:首页 > 谈天说地

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

34资源网2022-07-28393

本文实例为大家分享了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>

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

看完文章,还可以扫描下面的二维码下载快手极速版领4元红包

快手极速版二维码

快手极速版新人见面礼

除了扫码领红包之外,大家还可以在快手极速版做签到,看视频,做任务,参与抽奖,邀请好友赚钱)。

邀请两个好友奖最高196元,如下图所示:

快手极速版邀请好友奖励

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

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

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

分享给朋友:

相关文章

在爆破产品中内置芯片,「煋邦数码」让爆破产品被精准控制、全程追溯

在爆破产品中内置芯片,「煋邦数码」让爆破产品被精准控制、全程追溯

工业电雷管作为雷管的第二大品种,近几年已逐渐被数码电子雷管取代。 根据《民爆行业经济运行分析报告》显示,2020年工业雷管总产量为9.56亿发,其中电子雷管的产量和占比继续保持着高速增长。从近五年电子雷管产量变化情况看,2020年电子雷管产…

win7开始菜单设置在哪里(win7开始菜单变成经典模式)

win7开始菜单设置在哪里(win7开始菜单变成经典模式)

我们在用win7系统的时候,发现打开了一些程序后,会在开始菜单那里显示这些最近打开的程序。有些人不想把自己最近打开的程序显示在这里,那么怎么可以删除这些程序,或者彻底让这里不会显示最近打开程序呢?下面我来教大家删除或设置不显示最近打开的程序…

龚文祥真的破产了吗?

龚文祥真的破产了吗?

图源:摄图网 编者按:本文来自微信公众号十里村(ID:shilipxl),作者:村长住在十里村,创业邦经授权转载 各位村民好,我是村长。 号称团队不超过10个人,一年就能赚五千万的微商教父龚文祥破产了!!! 因此还上了各大平台的热搜榜,事…

李佳琦:三十而已

李佳琦:三十而已

编者按:本文转自何加盐(ID:ihejiayan),作者何加盐,题图@李佳琦 微博,创业邦经授权转载。 李佳琦,生于1992年5月。 这是我迄今为止,写过的最年轻的商业人物。 按年份来算,他还要过27天,才进入30岁;按生日来算,他还要再过…

联想G470怎么样换电池(联想G470详细拆卸图文教程)

联想G470怎么样换电池(联想G470详细拆卸图文教程)

一台联想G470客户描述不充电,在系统里面可以认到电池,拆机,G470修到不少了,大部分都是保护隔离第一个管子挂掉或者公共点短路,或者是CPU没供电等问题。那就测量一下保护隔离的几个管子吧,结果管子没有短路,测量充电芯片ISL6251的DC…

网吧收费系统有哪些(一般网吧收费标准)

网吧收费系统有哪些(一般网吧收费标准)

今天的主人公是经营管理网吧的小陆,他做了这样一个让顾客需求无法拒绝来网吧网络消费的理由。他给出的“理由”就是通过上网不要钱。 众所周知,网吧靠向顾客收取上网费来赚钱。现在上网不需要钱了。是不是因为他脑子坏了,赔钱的买卖还能做? 当然不是,…