Android ViewStub显示VISIBLE与消失GONE,Kotlin

Android ViewStub显示VISIBLE与消失GONE,Kotlin

Kotlin 复制代码
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewStub
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import androidx.tracing.Trace


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

    private var mCheckBox: MyView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_img)

        Log.d(TAG, "Trace.isEnabled()=${Trace.isEnabled()}")

        val viewStub = findViewById<ViewStub>(R.id.vs)
        val button = findViewById<Button>(R.id.button)
        var viewStubInflate: View? = null

        var show = false
        button.setOnClickListener {
            val label = "${TAG}:onClick"
            Trace.beginSection(label)

            show = !show
            Log.d(TAG, "show=$show")

            if (show) {
                if (viewStubInflate == null) {
                    viewStubInflate = viewStub.inflate()
                    mCheckBox = viewStubInflate?.findViewById<MyView>(R.id.cb)
                }

                viewStub.visibility = View.VISIBLE
                Log.d(TAG, "mCheckBox?.isChecked=${mCheckBox?.isChecked}")
            } else {
                viewStub.visibility = View.INVISIBLE
                Log.d(TAG, "mCheckBox?.isChecked=${mCheckBox?.isChecked}")
            }

            Trace.endSection()
        }
    }
}
XML 复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="100dp"
    android:orientation="vertical">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="切换" />

    <ViewStub
        android:id="@+id/vs"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout="@layout/layout_stub" />

    <View
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:background="@android:color/holo_blue_bright" />
</LinearLayout>

layout_stub.xml:

XML 复制代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/darker_gray">

    <com.app.MyView
        android:id="@+id/cb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="选择框" />
</RelativeLayout>
Kotlin 复制代码
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.util.Log
import androidx.appcompat.widget.AppCompatCheckBox
import androidx.tracing.Trace

class MyView : AppCompatCheckBox {
    companion object {
        const val TAG = "fly/MyView"
    }

    constructor(ctx: Context, attrs: AttributeSet? = null) : super(ctx, attrs) {
        val label = "${TAG}:constructor"
        Trace.beginSection(label)

        Log.d(TAG, "constructor")

        Trace.endSection()
    }

    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        super.onLayout(changed, left, top, right, bottom)

        val label = "${TAG}:onLayout"
        Trace.beginSection(label)

        Log.d(TAG, "onLayout")

        Trace.endSection()
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        Log.d(TAG, "onDraw")

        val label = "${TAG}:onDraw"
        Trace.beginSection(label)

        Log.d(TAG, "onDraw")

        Trace.endSection()
    }
}

Android ViewStub延迟初始化加载布局View,Kotlin_安卓延迟添加布局-CSDN博客文章浏览阅读492次,点赞3次,收藏10次。CPU返回后,会直接将GraphicBuffer提交给SurfaceFlinger,告诉SurfaceFlinger进行合成,但是这个时候GPU可能并未完成之前的图像渲染,这时候就牵扯到一个同步,Android中,用的是Fence机制,SurfaceFlinger合成前会查询Fence,如果GPU渲染没有结束,则等待GPU渲染结束,GPU结束后,会通知SurfaceFlinger进行合成,SF合成后,提交显示,最终完成图像的渲染显示。而对SF来说,只要有合成任务,它就得再去申请VSYNC-sf。_安卓延迟添加布局https://zhangphil.blog.csdn.net/article/details/145861445Android adb shell命令捕获systemtrace_android 抓trace-CSDN博客文章浏览阅读2.7k次,点赞2次,收藏8次。本文介绍了如何使用adbshell命令配合perfetto工具来捕获Android设备的systemtrace文件,包括设置跟踪时长、保存文件路径、将文件从设备拉取到电脑以及通过PerfettoUI分析trace文件。这个过程对于性能优化和问题排查非常有用。https://blog.csdn.net/zhangphil/article/details/131249820Android Trace埋点beginSection打tag标签,Kotlin_android trace.beginsection-CSDN博客文章浏览阅读1k次,点赞13次,收藏20次。本文介绍了如何使用adbshell命令配合perfetto工具来捕获Android设备的systemtrace文件,包括设置跟踪时长、保存文件路径、将文件从设备拉取到电脑以及通过PerfettoUI分析trace文件。返回的是false,原因是需要手机在 开发者选项 - 系统跟踪 - 录制轨迹 ,勾选后,才会有自己打的tag标签。抓trace是没有显示 fly_tag 这段trace的,并且,程序跑起来,上面trace打好tag标签后用,用。_android trace.beginsectionhttps://zhangphil.blog.csdn.net/article/details/145935055

相关推荐
Yang-Never28 分钟前
Kotlin协程 -> Job.join() 完整流程图与核心源码分析
android·开发语言·kotlin·android studio
XeonYu2 小时前
Kotlin 协程之 突破 Flow 限制:Channel 与 Flow 的结合之道
kotlin·coroutine·channelflow·callbackflow·receiveasflow·consumeasflow
XeonYu6 小时前
Kotlin 协程之 Flow 的理解使用及源码解析
kotlin·flow·coroutine
一笑的小酒馆6 小时前
Android性能优化之截屏时黑屏卡顿问题
android
懒人村杂货铺9 小时前
Android BLE 扫描完整实战
android
TeleostNaCl11 小时前
如何安装 Google 通用的驱动以便使用 ADB 和 Fastboot 调试(Bootloader)设备
android·经验分享·adb·android studio·android-studio·android runtime
fatiaozhang952712 小时前
中国移动浪潮云电脑CD1000-系统全分区备份包-可瑞芯微工具刷机-可救砖
android·网络·电脑·电视盒子·刷机固件·机顶盒刷机
低调小一12 小时前
Swift 语法学习指南 - 与 Kotlin 对比
微信·kotlin·swift
2501_9159184113 小时前
iOS 开发全流程实战 基于 uni-app 的 iOS 应用开发、打包、测试与上架流程详解
android·ios·小程序·https·uni-app·iphone·webview
lichong95113 小时前
【混合开发】vue+Android、iPhone、鸿蒙、win、macOS、Linux之dist打包发布在Android工程asserts里
android·vue.js·iphone