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 分钟前
【Android GLSurfaceView源码学习】第二天:GLSurfaceView深度分析
android·学习
元气满满-樱1 小时前
LNMP架构学习
android·学习·架构
starrycode8882 小时前
【每日一个知识点】Kotlin开发基础知识
ui·kotlin
allk552 小时前
Android 渲染性能优化实战总结:从监控体系到架构落地
android·性能优化·架构
思成不止于此2 小时前
C++红黑树封装map/set核心揭秘
android
走在路上的菜鸟2 小时前
Android学Dart学习笔记第十七节 类-成员方法
android·笔记·学习·flutter
歪楼小能手2 小时前
Android16底部导航栏添加音量加减虚拟按键
android·java·平板
又是努力搬砖的一年2 小时前
elasticsearch修改字段类型
android·大数据·elasticsearch
走在路上的菜鸟3 小时前
Android学Dart学习笔记第十八节 类-继承
android·笔记·学习·flutter
Colinnian3 小时前
Android Studio创建新项目时需要更改哪些地方
android·ide·android studio