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

相关推荐
毕设源码-朱学姐1 小时前
【开题答辩全过程】以 基于安卓的教师上课辅助系统为例,包含答辩的问题和答案
android
诸神黄昏EX2 小时前
Android Safety 系列专题【篇二:AVB签名】
android
2601_949543012 小时前
Flutter for OpenHarmony垃圾分类指南App实战:意见反馈实现
android·flutter
urkay-3 小时前
Android 中实现 HMAC-SHA256
android·开发语言·python
YIN_尹3 小时前
【MySQL】增删查改的艺术——数据库CRUD完全指南(下)
android·数据库·mysql
m0_748233173 小时前
PHP8.0新特性全解析
android
一起养小猫3 小时前
Flutter for OpenHarmony 实战:从零开发一款五子棋游戏
android·前端·javascript·flutter·游戏·harmonyos
●VON4 小时前
从像素到语义:React Native Text 组件在 OpenHarmony 上的渲染哲学与工程实现
android·react native·react.js
henysugar4 小时前
Android studio编译aidl若干问题记录
android·ide·android studio·aidl
阿斌_bingyu7094 小时前
FastAdmin 混合式语言包添加繁体中文(zh-tw)完整教程
android·ide