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

相关推荐
饭小猿人11 小时前
Android 腾讯X5WebView如何禁止系统自带剪切板和自定义剪切板视图
android·java
_李小白11 小时前
【android opencv学习笔记】Day 8: remap(像素位置重映射)
android·opencv·学习
美狐美颜SDK开放平台11 小时前
多场景美颜SDK解决方案:直播APP(iOS/安卓)开发接入详解
android·人工智能·ios·音视频·美颜sdk·第三方美颜sdk·短视频美颜sdk
嗷o嗷o12 小时前
Android BLE 里,MTU、分包和长数据发送到底该怎么处理
android
胡致和12 小时前
配置变更后,弹窗为什么飞到了最左边?
kotlin
Gary Studio13 小时前
Android AIDL HAL工程结构示例
android
y = xⁿ14 小时前
MySQL八股知识合集
android·mysql·adb
andr_gale14 小时前
04_rc文件语法规则
android·framework·aosp
祖国的好青年15 小时前
VS Code 搭建 React Native 开发环境(Windows 实战指南)
android·windows·react native·react.js