您好,登錄后才能下訂單哦!
這篇文章主要介紹“Android如何實(shí)現(xiàn)加載圈”,在日常操作中,相信很多人在Android如何實(shí)現(xiàn)加載圈問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Android如何實(shí)現(xiàn)加載圈”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
首先,直接上菊花效果圖,這是我直接從項(xiàng)目里面截取下來(lái)的。
核心代碼
import android.app.Dialog; import android.content.Context; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; public class CircularLoading { /** * 顯示Dialog * @param context 上下文對(duì)象 * @param msg 提示內(nèi)容 * @param isCancelable 是否可以點(diǎn)擊取消 * @return */ public static Dialog showLoadDialog(Context context, String msg, boolean isCancelable) { LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(R.layout.circular_loading, null); RelativeLayout layout = (RelativeLayout) v.findViewById(R.id.dialog_bg); // main.xml中的ImageView ImageView loadImage = (ImageView) v.findViewById(R.id.load_iv); TextView pointTextView = (TextView) v.findViewById(R.id.point_tv); // 加載動(dòng)畫(huà) Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(context, R.anim.rotating_animation); // 使用ImageView顯示動(dòng)畫(huà) loadImage.startAnimation(hyperspaceJumpAnimation); pointTextView.setText(msg); Dialog loadingDialog = new Dialog(context, R.style.TransDialogStyle); loadingDialog.setContentView(layout); loadingDialog.setCancelable(isCancelable); loadingDialog.setCanceledOnTouchOutside(false); Window window = loadingDialog.getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); lp.width = WindowManager.LayoutParams.WRAP_CONTENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; window.setGravity(Gravity.CENTER); window.setAttributes(lp); window.setWindowAnimations(R.style.PopWindowAnimStyle); loadingDialog.show(); return loadingDialog; } /** * 關(guān)閉dialog */ public static void closeDialog(Dialog mCircularLoading) { if (mCircularLoading != null && mCircularLoading.isShowing()) { mCircularLoading.dismiss(); } } }
布局文件
circular_loading.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialog_bg" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#000000" android:minHeight="60dp" android:minWidth="150dp" android:orientation="horizontal" > <ImageView android:id="@+id/load_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="20dp" android:layout_marginStart="20dp" android:src="@drawable/dialog_loading_img" /> <TextView android:id="@+id/point_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:layout_marginTop="0dp" android:layout_toRightOf="@+id/load_iv" android:ellipsize="middle" android:singleLine="true" android:textSize="16sp" /> </RelativeLayout>
動(dòng)畫(huà)
rotating_animation.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <rotate android:duration="1000" android:fromDegrees="0" android:interpolator="@android:anim/linear_interpolator" android:pivotX="50%" android:pivotY="50%" android:repeatCount="-1" android:repeatMode="restart" android:toDegrees="360" />
dialog_show.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0" android:toAlpha="1.0"/> </set>
dialog_hide.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="1.0" android:toAlpha="0"/> </set>
Style
</style> <style name="TransDialogStyle" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> <item name="android:background">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:backgroundDimEnabled">true</item> <item name="android:backgroundDimAmount">0.5</item> <item name="android:windowFullscreen">true</item> </style> </style> <style name="PopWindowAnimStyle"> <item name="android:windowShowAnimation">@anim/dialog_show</item> <item name="android:windowHideAnimation">@anim/dialog_hide</item> </style>
使用方法
//顯示 mCircularLoading = CircularLoading.showLoadDialog(Dvr_Activity_Main.this, "加載中...", true); //關(guān)閉 CircularLoading.closeDialog(mCircularLoading);
到此,關(guān)于“Android如何實(shí)現(xiàn)加載圈”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。