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

相关推荐
-SOLO-8 小时前
备份apk 工具
android
私人珍藏库12 小时前
【Android】BotHub-多模型AI机器人聚合库-内置免费模型
android·人工智能·智能手机·app·工具·多功能
普马萨特13 小时前
Wi-Fi 扫描频率限制与 Android 演进全解析
android
张拭心13 小时前
Android 17 新特性:后台音频交互限制加强
android·前端
张拭心13 小时前
Android 17 新特性:ProfilingManager 新触发器
android·前端
张拭心14 小时前
Android 17 新特性:MessageQueue 无锁实现
android·前端
brycegao14 小时前
如何搭建标准化 Git 工具流,保障 Android 团队代码质量
android·ci/cd
AI科技星14 小时前
数术江湖·全卷合集 - 硬核江湖・数理史诗
android·人工智能·架构·概率论·学习方法
五月君_14 小时前
安卓也支持了!微信链接 Claude Code 保姆级教程
android·微信
柚鸥ASO优化14 小时前
一篇讲透安卓ASO!开发者千万别只盯着iOS了
android·ios·aso优化