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

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

34资源网2022-07-28547

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

分享给朋友:

相关文章

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

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

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

养成良好的习惯,做一名有品位的教师

养成良好的习惯,做一名有品位的教师

陶行知先生说:“思想决定行动,行动养成习惯,习惯形成品质,品质决定命运”。最近从网上读了《影响教师一生的100个好习惯》一书,不禁对陶先生这句话有了更深刻的领悟和理解。阅读本书带给我的不仅是享受,更多的则是生活的引领,智慧的传递和方法的教授…

手机拍视频软件哪个好用(新手拍好人像摄影技巧)

手机拍视频软件哪个好用(新手拍好人像摄影技巧)

每一个热爱生活的人都关注了“手机摄影技巧”…

引流文案微信推广(微商引流推广文案模板)

引流文案微信推广(微商引流推广文案模板)

大家好啊!今天又跟大家分享小技巧啦~往下看↓↓↓ 首先说一下什么样的文案是引流型的?实际上,一句话是将公共域流量定向到您的私有域流量池。其目的是先引流然后慢慢进行信任激活变现。 在标题方面,通常有以下几种类型,今天为大家详细描述一下。 一…

逍遥手机模拟器怎么用(逍遥安卓模拟器详细使用教程)

逍遥手机模拟器怎么用(逍遥安卓模拟器详细使用教程)

真正的5V5公平竞技对战,传承端游纯正体验。人气英雄,经典还原;公平竞技,实力至上;峡谷传说,掌心再现。策略、战术、意识、配合,在移动端重现峡谷战场乐趣。 为了庆祝大家期待已久的中国区开服,官方也带来了五大福利活动,用户可免费参与,并获得十…

购买须知模板怎么编辑(淘宝买家须知免费素材)

购买须知模板怎么编辑(淘宝买家须知免费素材)

为了帮助您入门,在您注册 Shopify 帐户时,后台的模版页面中会设置一个默认模版。如果您想为在线商店自定义一个不同的模版,则需要向后台添加一个模版。 您可通过以下几种方式添加模版: 如果您的计算机上的 .zip 文件中已有一个模版,那么…