Android 加载动画逐帧动画透明d窗

Android 加载动画逐帧动画透明d窗,第1张

概述1.效果截图2.LoadingDialog代码publicclassLoadingDialogextendsDialog{privateAnimationDrawablemAnimation;privatefinalStringmLoadingTitle;privatefinalintlayout;publicLoadingDialog(Contextcontext,Stringcontent,intlayou 1. 效果截图

2. LoadingDialog代码
public class LoadingDialog extends Dialog {    private AnimationDrawable mAnimation;    private final String mloadingTitle;    private final int layout;    public LoadingDialog(Context context, String content, int layout) {        super(context);        this.mloadingTitle = content;        this.layout = layout;        //点击外围取消        setCanceledOntouchOutsIDe(true);    }    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        //设置窗口布局        setContentVIEw(R.layout.progress_dialog);        ImageVIEw mImageVIEw = findVIEwByID(R.ID.loadingIv);        //设置动画资源        mImageVIEw.setimageResource(layout);        mAnimation = (AnimationDrawable) mImageVIEw.getDrawable();        // 启动动态图话        mImageVIEw.postDelayed(mAnimation::start, 100);        TextVIEw mloadingTv = findVIEwByID(R.ID.loadingTv);        //设置加载文字        mloadingTv.setText(mloadingTitle);        // <color name="transparent">#00FFFFFF</color>        //设置透明        getwindow().setBackgroundDrawableResource(R.color.transparent);    }}
3. 调用窗口代码
public class MainActivity extends AppCompatActivity {    private LoadingDialog loadingDialog;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        findVIEwByID(R.ID.show).setonClickListener(v -> {            if (loadingDialog == null) {                //创建                loadingDialog = new LoadingDialog(MainActivity.this, "正在加载", R.drawable.anim_loading);            }            //调用            loadingDialog.show();        });    }}
4. LoadingDialog布局——progress_dialog.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_gravity="center"    androID:gravity="center"    androID:orIEntation="vertical">    <ImageVIEw        androID:ID="@+ID/loadingIv"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:contentDescription="@string/loading" />    <TextVIEw        androID:ID="@+ID/loadingTv"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:textcolor="@color/black"        androID:textSize="20sp" /></linearLayout>
5. 调用窗口布局——activity_main.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_gravity="center"    androID:gravity="center"    androID:orIEntation="vertical">    <button        androID:ID="@+ID/show"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_margin="16dp"        androID:background="@color/black"        androID:text="@string/show"        androID:textcolor="#ffffff" /></linearLayout>
6. 动画文件——anim_loading.xml
<?xml version="1.0" enCoding="utf-8"?><animation-List xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:oneshot="false" >    <item        androID:drawable="@drawable/loading_01"        androID:duration="200"/>    <item        androID:drawable="@drawable/loading_02"        androID:duration="200"/>    <item        androID:drawable="@drawable/loading_03"        androID:duration="200"/>    <item        androID:drawable="@drawable/loading_04"        androID:duration="200"/>    <item        androID:drawable="@drawable/loading_05"        androID:duration="200"/>    <item        androID:drawable="@drawable/loading_06"        androID:duration="200"/>    <item        androID:drawable="@drawable/loading_07"        androID:duration="200"/>    <item        androID:drawable="@drawable/loading_08"        androID:duration="200"/>    <item        androID:drawable="@drawable/loading_09"        androID:duration="200"/>    <item        androID:drawable="@drawable/loading_10"        androID:duration="200"/>    <item        androID:drawable="@drawable/loading_11"        androID:duration="200"/>    <item        androID:drawable="@drawable/loading_12"        androID:duration="200"/></animation-List>
7. 透明色彩
<color name="transparent">#00FFFFFF</color>

参考链接:https://www.runoob.com/w3cnote/androID-tutorial-progressbar.HTML
源码及素材地址:https://github.com/WindSNowli/androID-tools
源码及素材地址:https://gitee.com/windsNowli/androID-tools

总结

以上是内存溢出为你收集整理的Android 加载动画逐帧动画透明d窗全部内容,希望文章能够帮你解决Android 加载动画逐帧动画透明d窗所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1005002.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存