当前位置: 首页 > news >正文

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

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

 

 

implementation "androidx.asynclayoutinflater:asynclayoutinflater:1.1.0-alpha01"

 

 



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 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>

 

 



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

 

相关文章:

  • CentOS 7 日志切割实战:Logrotate 详解与配置指南
  • 剑指 Offer II 031. 最近最少使用缓存
  • excel单、双字节字符转换函数(中英文输入法符号转换)
  • 鸿蒙-AVPlayer
  • smolagents学习笔记系列(七)Examples-Self-correcting Text-to-SQL
  • Java一揽子集合整理
  • 网页制作09-html,css,javascript初认识のhtml如何使用表单
  • 数据安全管理的AI工具有哪些?
  • [LeetCode]day29 232.用栈实现队列
  • ZT16 小欧的括号嵌套
  • Linux网络之传输层协议(UDP,TCP协议)
  • 【转】Python for Data Analysis第二版【中文版】-第三章
  • 24.[前端开发-JavaScript基础]Day01-插件配置-变量-数据
  • React低代码项目:Redux 状态管理
  • Redis|复制 REPLICA
  • Rust学习总结之-枚举
  • 半导体晶圆精控:ethercat转profient网关数据提升制造精度
  • 2024中国信通院“集智”蓝皮书合集(附下载)
  • Windows-内核
  • 解决免费 PDF 发票打印痛点的实用工具
  • 乌副总理:乌美签署矿产协议
  • 空调+零食助顶级赛马备战,上海环球马术冠军赛即将焕新登场
  • 证监会副主席王建军被查
  • “面具女孩”多次恐吓电梯内两幼童,当事女孩及家长道歉后获谅解
  • 民生访谈|支持外贸企业拓内销,上海正抓紧制定便利措施
  • 澎湃回声丨23岁小伙“被精神病”8年续:今日将被移出“重精”管理系统