最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義加載框效果

 更新時間:2021年08月18日 17:03:02   作者:臥龍躍馬  
這篇文章主要為大家詳細介紹了Android自定義加載框效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android自定義加載框效果的具體代碼,供大家參考,具體內(nèi)容如下

效果圖

菊花圖標(mipmap-xxhdpi)

加載框圓角背景drawable

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="12dp" />
    <solid android:color="@color/transparent_black"/>
</shape>

布局文件

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_message_dialog"
        android:minWidth="132dp"
        android:minHeight="100dp"
        android:padding="15dp">

        <ImageView
            android:id="@+id/iv"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:src="@mipmap/ic_loading"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toTopOf="@id/tv"/>

        <TextView
            android:id="@+id/tv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textSize="12sp"
            android:textColor="@color/white"
            android:layout_marginTop="15dp"
            android:text="@string/loading"
            android:lineSpacingExtra="8dp"
            android:gravity="center_horizontal"
            app:layout_constraintTop_toBottomOf="@id/iv"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            />
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

LoadingDialog.kt

package com.lzk.libcommon.widget

import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.animation.LinearInterpolator
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import com.blankj.utilcode.util.LogUtils
import com.lzk.libcommon.R
import com.lzk.libcommon.databinding.ViewLoadingDialogBinding

/**
 * @Author: LiaoZhongKai
 * @Date: 2021/7/14 9:04
 * @Description: 加載框
 */
class LoadingDialog: DialogFragment() {

    private var mTips: String? = null
    private lateinit var mLoadingDialogBinding: ViewLoadingDialogBinding
    private lateinit var mAnimation: ObjectAnimator

    override fun onStart() {
        super.onStart()
        //去掉DialogFragment外部的背景色
        dialog?.window?.apply {
            attributes = attributes.apply {
            //======================這里設(shè)置背景陰影透明度===============
            //======================0是全透明===========================
                dimAmount = 0.0f
            }
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        mLoadingDialogBinding = DataBindingUtil.inflate(inflater, R.layout.view_loading_dialog,container,false)

        dialog?.apply {
            requestWindowFeature(Window.FEATURE_NO_TITLE)
            setCanceledOnTouchOutside(false)
            window?.apply {
                //去掉DialogFragment內(nèi)部的背景色
                setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
                //去掉Padding
                decorView.setPadding(0,0,0,0)
            }
        }
        return mLoadingDialogBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        rotate()
        setTips(mTips)
    }

    private fun rotate(){
        mAnimation = ObjectAnimator.ofFloat(mLoadingDialogBinding.iv,"rotation",360f).apply {
            repeatCount = ObjectAnimator.INFINITE
            repeatMode = ValueAnimator.RESTART
            interpolator = LinearInterpolator()
            duration = 1000
        }
        mAnimation.start()
    }

    override fun onDestroyView() {
        super.onDestroyView()
        mAnimation.cancel()
    }

    //顯示
    fun showDialog(fragmentManager: FragmentManager, msg: String? = null){
        mTips = msg
        if (isVisible){
            dismiss()
        }
        show(fragmentManager,"")
    }
    //隱藏
    fun dismissDialog(){
        if (isAdded){
            dismiss()
            mTips = null
        }
    }

    /**
     * 設(shè)置加載提示文字
     */
    private fun setTips(msg: String?): LoadingDialog{
        mLoadingDialogBinding.tv.visibility = if (msg.isNullOrEmpty()) View.GONE else View.VISIBLE
        if (!msg.isNullOrEmpty()){
            mLoadingDialogBinding.tv.text = msg
        }
        return this
    }
}

基類封裝

abstract class BaseVMActivity<T: ViewDataBinding,VM: BaseViewModel> : AppCompatActivity(){
 private var mLoadingDialog: LoadingDialog? = null

   override fun onDestroy() {
        super.onDestroy()
        mLoadingDialog?.dismissDialog()
        mLoadingDialog = null
    }


 /**
     * 顯示加載彈框
     */
    fun showLoadingDialog(msg: String? = null){
        mLoadingDialog = LoadingDialog()
        mLoadingDialog!!.showDialog(supportFragmentManager,msg)
    }

    /**
     * 隱藏加載彈框
     */
    fun dismissLoadingDialog(){
        mLoadingDialog?.dismissDialog()
    }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android SeekBar實現(xiàn)禁止滑動

    Android SeekBar實現(xiàn)禁止滑動

    這篇文章主要為大家詳細介紹了Android SeekBar實現(xiàn)禁止滑動,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-03-03
  • 利用Android實現(xiàn)比較炫酷的自定義View

    利用Android實現(xiàn)比較炫酷的自定義View

    自定義View、多線程、網(wǎng)絡(luò),被認為是Android開發(fā)者必須牢固掌握的最基礎(chǔ)的三大基本功,這篇文章主要給大家介紹了關(guān)于如何利用Android實現(xiàn)比較炫酷的自定義View的相關(guān)資料,需要的朋友可以參考下
    2021-07-07
  • Android wifi 調(diào)試詳解及簡單實例

    Android wifi 調(diào)試詳解及簡單實例

    這篇文章主要介紹了Android wifi 調(diào)試詳解及簡單實例的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • Android中的Bitmap序列化失敗的解決方法

    Android中的Bitmap序列化失敗的解決方法

    這篇文章主要介紹了Android中的Bitmap序列化失敗的解決方法,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-11-11
  • Android實現(xiàn)底部導(dǎo)航欄的主界面

    Android實現(xiàn)底部導(dǎo)航欄的主界面

    這篇文章主要為大家詳細介紹了Android實現(xiàn)底部導(dǎo)航欄的主界面 ,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • Android實現(xiàn)界面內(nèi)嵌多種卡片視圖(ViewPager、RadioGroup)

    Android實現(xiàn)界面內(nèi)嵌多種卡片視圖(ViewPager、RadioGroup)

    這篇文章主要為大家詳細介紹了Android實現(xiàn)界面內(nèi)嵌多種卡片視圖,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • autojs模仿QQ長按彈窗菜單實現(xiàn)示例

    autojs模仿QQ長按彈窗菜單實現(xiàn)示例

    這篇文章主要為大家介紹了autojs模仿QQ長按彈窗菜單實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • Kotlin中實現(xiàn)多線程數(shù)據(jù)刷新的完整方案

    Kotlin中實現(xiàn)多線程數(shù)據(jù)刷新的完整方案

    這篇文章主要介紹了Kotlin中實現(xiàn)多線程數(shù)據(jù)刷新的完整方案,本文通過實例代碼給大家介紹的非常詳細,感興趣的朋友一起看看吧
    2025-04-04
  • Android通過LIstView顯示文件列表的兩種方法介紹

    Android通過LIstView顯示文件列表的兩種方法介紹

    過ListView顯示SD卡中的文件列表一共有兩種方法,一是:通過繼承ListActivity顯示;二是:利用BaseAdapter顯示,具體實現(xiàn)如下,感興趣的朋友可以參考下哈
    2013-06-06
  • Android學習筆記之藍牙功能

    Android學習筆記之藍牙功能

    這篇文章主要為大家詳細介紹了Android學習筆記之藍牙功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-09-09

最新評論

奉新县| 祁阳县| 乌拉特前旗| 定南县| 岱山县| 棋牌| 美姑县| 仙居县| 新兴县| 黄骅市| 邻水| 鹿泉市| 岑溪市| 秀山| 巢湖市| 米脂县| 介休市| 温州市| 蒙阴县| 南充市| 大方县| 凤翔县| 循化| 镇赉县| 长泰县| 唐河县| 凤翔县| 班戈县| 平顺县| 吴桥县| 泽州县| 游戏| 台中市| 靖远县| 井陉县| 历史| 延庆县| 泽普县| 廉江市| 诏安县| 东丽区|