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

相关推荐
Nathan202406162 小时前
Room - 基本使用及使用问题
android·面试·android jetpack
攻城狮_Dream4 小时前
基于 Python 的项目管理系统开发
android·数据库·python
C0Lin4 小时前
Kotlin 随记 (1)
开发语言·kotlin
迷路国王4 小时前
kotlin 知识点一 变量和函数
android·开发语言·kotlin
jiet_h5 小时前
自定义ToolbarView实战指南(Kotlin版)
android·开发语言·kotlin
缘来的精彩7 小时前
Android SDK封装打包流程详解
android
迷路国王8 小时前
kotlin 知识点 七 泛型的高级特性
开发语言·python·kotlin
yzpyzp8 小时前
kotlin的lateinit声明 的变量可能为null吗?
kotlin
没有晚不了安9 小时前
2.11作业
android