亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android 自定義加載動畫Dialog彈窗效果的示例代碼

 更新時間:2020年06月05日 10:18:13   作者:初學(xué)者-Study  
這篇文章主要介紹了Android 自定義加載動畫Dialog彈窗效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

效果圖

在這里插入圖片描述

在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

首先是創(chuàng)建彈窗的背景

在這里插入圖片描述

這是上面用到的
shape_bg_5_blue.xml為例,其他的三個無非就是里面的顏色不一樣而已

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
 <corners android:radius="5dp"/>
 <solid android:color="#1C285B"/>
</shape>

然后是圖片

在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

因?yàn)橛幸粋€是白色的所以你看不見,但是依然可以保存到你本地文件夾下。

然后就是創(chuàng)建一個彈窗的樣式

在這里插入圖片描述

<!-- 自定義loading dialog -->
 <style name="loading_dialog" parent="android:style/Theme.Dialog">
 <item name="android:windowFrame">@null</item>
 <item name="android:windowNoTitle">true</item>
 <item name="android:windowBackground">@drawable/shape_bg_5_yellow</item>
 <item name="android:windowIsFloating">true</item>
 <item name="android:windowContentOverlay">@null</item>
 </style>

通過這個android:windowBackground的值改變不同的彈窗背景。
然后就是一個動畫文件

在這里插入圖片描述

這個文件一定要放在anim文件夾下(PS:什么?你說你沒有這個文件夾?沒有你就創(chuàng)建一個啊,我的天!)
loading_animation.xml代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android">
 <rotate
 android:interpolator="@android:anim/linear_interpolator"
 android:pivotX="50%"
 android:pivotY="50%"
 android:fromDegrees="0"
 android:toDegrees="+360"
 android:duration="1500"
 android:startOffset="-1"
 android:repeatMode="restart"
 android:repeatCount="-1"/>
</set>

下面就要創(chuàng)建一個現(xiàn)實(shí)內(nèi)容的布局

在這里插入圖片描述

布局代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/dialog_view"
 android:orientation="vertical"
 android:layout_width="120dp"
 android:layout_height="120dp"
 android:gravity="center"
 android:padding="10dp">

 <ImageView
 android:id="@+id/iv_loading"
 android:layout_width="40dp"
 android:layout_height="40dp"
 android:src="@mipmap/icon_loading_5" />

 <TextView
 android:id="@+id/tv_loading_tx"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginTop="10dp"
 android:maxLines="1"
 android:text="玩命加載中..."
 android:textColor="#FFF"
 android:textSize="14sp" />
</LinearLayout>

接下來就是自定義Dialog

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Gravity;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 自定義彈窗
 */
public class CustomDialog extends Dialog {

 TextView tvLoadingTx;
 ImageView ivLoading;

 public CustomDialog(Context context) {
 this(context, R.style.loading_dialog, "玩命加載中...");

 }

 public CustomDialog(Context context, String string) {
 this(context, R.style.loading_dialog, string);
 }

 protected CustomDialog(Context context, int theme, String string) {
 super(context, theme);
 setCanceledOnTouchOutside(true);//點(diǎn)擊其他區(qū)域時 true 關(guān)閉彈窗 false 不關(guān)閉彈窗
 setContentView(R.layout.loading_dialog);//加載布局
 tvLoadingTx = findViewById(R.id.tv_loading_tx);
 tvLoadingTx.setText(string);
 ivLoading = findViewById(R.id.iv_loading);
 // 加載動畫
 Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
  context, R.anim.loading_animation);
 // 使用ImageView顯示動畫
 ivLoading.startAnimation(hyperspaceJumpAnimation);

 getWindow().getAttributes().gravity = Gravity.CENTER;//居中顯示
 getWindow().getAttributes().dimAmount = 0.5f;//背景透明度 取值范圍 0 ~ 1
 }

	//關(guān)閉彈窗
 @Override
 public void dismiss() {
 super.dismiss();
 }

使用

在這里插入圖片描述

這應(yīng)該能看懂吧,寫完收工。

總結(jié)

到此這篇關(guān)于Android 自定義加載動畫Dialog彈窗效果的示例代碼的文章就介紹到這了,更多相關(guān)Android 自定義加載 Dialog彈窗內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論