【发布时间】:2020-04-17 19:15:49
【问题描述】:
如何避免检查印刷机上的大量图像以减少延迟?我想通过不丢失检查功能尽快使TextView1 变为绿色。
TextView1.setOnClickListener {
if (image_view.drawable.constantState == ContextCompat.getDrawable(
this,
R.drawable.cat__1_
)?.constantState ||
image_view.drawable.constantState == ContextCompat.getDrawable(
this,
R.drawable.cat__2_
)?.constantState ||
image_view.drawable.constantState == ContextCompat.getDrawable(
this,
R.drawable.cat__3_
)?.constantState ||
image_view.drawable.constantState == ContextCompat.getDrawable(
this,
R.drawable.cat__4_
)?.constantState
) {
TextView1.setBackgroundResource(R.color.green);
Handler().postDelayed({
TextView1.setBackgroundResource(R.color.white)
}, 50)
}
已编辑:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
showGreen = false
TextView1.setOnClickListener {
showGreen = isGreenBackgroundShouldAppear()
}
}
fun isGreenBackgroundShouldAppear(): Boolean {
return image_view.drawable.constantState == ContextCompat.getDrawable(
this,
R.drawable.cat__1_
)?.constantState ||
image_view.drawable.constantState == ContextCompat.getDrawable(
this,
R.drawable.cat__2_
)?.constantState ||
image_view.drawable.constantState == ContextCompat.getDrawable(
this,
R.drawable.cat__3_
)?.constantState ||
image_view.drawable.constantState == ContextCompat.getDrawable(
this,
R.drawable.cat__4_
)?.constantState
// Do the checking here
// and set the showGreen variable
}
【问题讨论】:
-
您实际上是在处理程序中使用延迟?你们用什么来减少延迟?那里没有异步,只是简单的线性代码将可运行的内容移动到条件流的底部