Android AsyncLayoutInflater异步加载xml布局文件,Kotlin

Android AsyncLayoutInflater异步加载xml布局文件,Kotlin

Kotlin 复制代码
implementation "androidx.asynclayoutinflater:asynclayoutinflater:1.1.0-alpha01"
Kotlin 复制代码
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.asynclayoutinflater.view.AsyncLayoutInflater

class MyActivity : AppCompatActivity() {
    companion object {
        const val TAG = "fly/MyActivity"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.d(TAG, "onCreate开始...")

        AsyncLayoutInflater(this).inflate(R.layout.activity_my, null, object : AsyncLayoutInflater.OnInflateFinishedListener {
            override fun onInflateFinished(view: View, resid: Int, parent: ViewGroup?) {
                Log.d(TAG, "onInflateFinished")
                setContentView(view)
            }
        })

        Log.d(TAG, "onCreate结束")
    }
}
XML 复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="hello,world!" />

    <com.appdemo.MyLongTimeView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@mipmap/image" />
</LinearLayout>
Kotlin 复制代码
import android.content.Context
import android.util.AttributeSet
import android.util.Log
import androidx.appcompat.widget.AppCompatImageView

class MyLongTimeView : AppCompatImageView {
    companion object {
        const val TAG = "fly/MyLongTimeView"
    }

    constructor(ctx: Context, attribute: AttributeSet) : super(ctx, attribute) {
        Log.d(TAG, "开始sleep...")
        Thread.sleep(6000)
        Log.d(TAG, "sleep结束")
    }
}

Android ViewStub延迟初始化加载布局View,Kotlin-CSDN博客文章浏览阅读274次。CPU返回后,会直接将GraphicBuffer提交给SurfaceFlinger,告诉SurfaceFlinger进行合成,但是这个时候GPU可能并未完成之前的图像渲染,这时候就牵扯到一个同步,Android中,用的是Fence机制,SurfaceFlinger合成前会查询Fence,如果GPU渲染没有结束,则等待GPU渲染结束,GPU结束后,会通知SurfaceFlinger进行合成,SF合成后,提交显示,最终完成图像的渲染显示。而对SF来说,只要有合成任务,它就得再去申请VSYNC-sf。https://blog.csdn.net/zhangphil/article/details/145861445

相关推荐
明道源码42 分钟前
Kotlin 控制流、函数、Lambda、高阶函数
android·开发语言·kotlin
橙子1991101642 分钟前
在 Kotlin 中,ViewModel 的获取
开发语言·vue.js·kotlin
hweiyu001 小时前
Gradle 构建脚本迁移:从 Groovy DSL 到 Kotlin DSL,语法与技巧对比
开发语言·kotlin·gradle
消失的旧时光-19431 小时前
搞懂 Kotlin 的 List、Set、Map、HashMap、LinkedHashMap,以及 asSequence() 的底层原理与实战场景。
kotlin·数据处理·1024程序员节
明道源码1 小时前
Kotlin 面向对象编程、主构造函数、次构造函数、伴生对象、数据类、继承
kotlin·1024程序员节
消失的旧时光-19433 小时前
Kotlin × Gson:为什么遍历 JsonObject 要用 entrySet()
android·kotlin·数据处理·1024程序员节
G果4 小时前
安卓APP页面之间传参(Android studio 开发)
android·java·android studio
曾凡宇先生5 小时前
无法远程连接 MySQL
android·开发语言·数据库·sql·tcp/ip·mysql·adb
zhangphil7 小时前
Android GPU的RenderThread Texture upload上传Bitmap优化prepareToDraw
android
柿蒂8 小时前
聊聊SliverPersistentHeader优先消费滑动的设计
android·flutter