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

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

34资源网2022-07-28634

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

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

版权声明:34楼发布

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

分享给朋友:

相关文章

37句老师的经典励志短句

37句老师的经典励志短句

1、无知者无畏并不可怕,真正可怕的是无知者还无所谓。请你记住:不要用无所谓的态度原谅自己,对待一切,那会使一切变得对你无所谓,也会使你成为一个无所谓而又无所成的痛苦的边缘人。…

免费的包子,好心做了好事却害了自己

免费的包子,好心做了好事却害了自己

中午与老板一块吃饭,听到了一个老好人事件。就是一包子铺老板许坤免费送人包子事件!这是个真实的事件,现在网上有流传,下边的内容来源于某个平台,大家一起来看看吧。…

互联网公司好日子到头,逻辑彻底变了

互联网公司好日子到头,逻辑彻底变了

好日子到头了,逻辑彻底变了,互联网公司已经不再是香饽饽。有两个重要的信号。…

融资丨「PPIO边缘云」完成亿元A1轮融资,刷新边缘云领域融资记录

融资丨「PPIO边缘云」完成亿元A1轮融资,刷新边缘云领域融资记录

创业邦获悉,近日,边缘云公司PPIO宣布完成过亿元A1轮融资,由创世伙伴、张江科投、磐霖资本等多家机构联合投资,Pre-A轮投资方蓝驰创投、沸点资本及华业天成继续追加投资,光源资本担任融资财务顾问。这是公司半年内再次获投资人支持,公司A2轮…

裁员,爱奇艺穿越生死线

裁员,爱奇艺穿越生死线

图源:摄图网 编者按:本文来自微信公众号霞光社(ID:Globalinsights)),作者:麻吉、郭照川、韩夏,创业邦经授权转载 霞光社从多位爱奇艺员工处了解到,本轮裁员罕见覆盖了爱奇艺所有部门,从影业、IP、游戏、电商部门,甚至到经纪公…