Android ViewStub显示VISIBLE与消失GONE,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 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 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>
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.beginsection
https://zhangphil.blog.csdn.net/article/details/145935055